//
//  KLineChart.m
//  Stock_Pro
//
//  Created by imuse on 10-12-18.
//  Copyright 2010 gaotime. All rights reserved.
//

#import "KLineChart.h"
#import "ShowFormat.h"
#import "ColorTools.h"
#import "QuoteLvKIndex.h"
#import "HZMinPriceModel.h"
#import "MAModifyView.h"

#import "QuoteLvOper.h"
extern QUOTELV_OPER *g_pQuoteOper;

#define GAP_X 10
#define KPOINT_WIDTH 1
#define TITLE_HEIGHT 22
#define TOOLS_BAR_HEIGHT 30
#define VOL_TITLE_HEIGHT	30
//#define LEFT_WIDTH	50
//#define RIGHT_WIDTH 10
#define LEFT_WIDTH(a) (a? 50:3)       //框图左侧距离
#define RIGHT_WIDTH(b) (b? 10:3)        //框图右侧距离
#define LEFT_GAP_WIDTH 50
#define AGIN(a) (a? 0:2)
#define BUTTON_WIDTH 30

#define SA_WIDTH 1

#define KDJ_0_100(i) (i>100? 100:i<0?0:i)

#define kArrowBtnW 20

@implementation KLineChart
@synthesize delegate = _delegate,isLandscape;

- (instancetype)initWithFrame:(CGRect)frame{
    return [self initWithFrame:CGRectZero withParent:nil];
}

- (id)initWithFrame:(CGRect)frame withParent:(id)parent
{
	if ((self = [super initWithFrame:frame])) {
        // Initialization code
		
		self.backgroundColor = [UIColor clearColor];
		
		//temp clac 
		int nKMaxNum = (480-LEFT_WIDTH(isLandscape) - RIGHT_WIDTH(isLandscape) -2)/(KPOINT_WIDTH+1);
		
		int nSize;
		nSize = sizeof(GUI_RECT)*nKMaxNum;
		pRectUp = Tools_Malloc(nSize);
		pRectDown = Tools_Malloc(nSize);
		
		pRectUpVol = Tools_Malloc(nSize);
		pRectDownVol = Tools_Malloc(nSize);
		
		nSize = sizeof(K_POINT_HL)*nKMaxNum;
		pUp = Tools_Malloc(nSize);
		pDown = Tools_Malloc(nSize);
		
		nSize = sizeof(GUI_POINT)*nKMaxNum;
		pLine5 = Tools_Malloc(nSize);
		pLine10 = Tools_Malloc(nSize);
		pLine20 = Tools_Malloc(nSize);
    pLine60 = Tools_Malloc(nSize);
		
		pLineK = Tools_Malloc(nSize);
		pLineD = Tools_Malloc(nSize);
		pLineJ = Tools_Malloc(nSize);
		
		pLineRSI6 = Tools_Malloc(nSize);
		pLineRSI12 = Tools_Malloc(nSize);
		pLineRSI24 = Tools_Malloc(nSize);
		
		pLineDIF = Tools_Malloc(nSize);
		pLineDEA = Tools_Malloc(nSize);
		pLineDDUp = Tools_Malloc(nSize);
		pLineDDDown = Tools_Malloc(nSize);
		
		pLineWR1 = Tools_Malloc(nSize);
		pLineWR2 = Tools_Malloc(nSize);

		pLineBIAS1 = Tools_Malloc(nSize);
		pLineBIAS2 = Tools_Malloc(nSize);
		pLineBIAS3 = Tools_Malloc(nSize);
		
		pLineAR = Tools_Malloc(nSize);
		pLineBR = Tools_Malloc(nSize);
		
		pLineCCI = Tools_Malloc(nSize);
		
		pLineDDD = Tools_Malloc(nSize);
		pLineAMA = Tools_Malloc(nSize);
		
		pLinePSY = Tools_Malloc(nSize);
		
		pLineMID = Tools_Malloc(nSize);
		pLineUPPER = Tools_Malloc(nSize);
		pLineLOWER = Tools_Malloc(nSize);
		
		nSize = sizeof(K_POINT_BOLL)*nKMaxNum;
		pBollUp = Tools_Malloc(nSize);
		pBollDown = Tools_Malloc(nSize);
    
    //lisz add 20110916 start
		nSize = sizeof(GUI_RECT)*nKMaxNum;
    pLineDDXUp = Tools_Malloc(nSize);
    pLineDDXDown = Tools_Malloc(nSize);
		nSize = sizeof(GUI_POINT)*nKMaxNum;
    pDDX1 = Tools_Malloc(nSize);
    pDDX2 = Tools_Malloc(nSize);
    pDDX3 = Tools_Malloc(nSize);
    //lisz add 20110916 end

		nUpLen = 0;
		nDownLen = 0;
		nPosStart = 0;
		nKLineWidth = 7;
		
		bIsCalcStartPos = YES;
		
		nPos = -1;
		
		nMTDistance = 15;
		
		nLineExType = KLINE_EX_TYPE_VOL;
		
		self.multipleTouchEnabled = YES;
		//add by jason
		n_Mode = KLINE_MODE_NORMAL;
		//end
		//新版
    bgColor = 0xe8f5f7;
		nM5Color = 0xff51f9;
		nM10Color = 0xf6bb42;
		nM20Color = 0x5d9cec;
    nM60Color = 0x888888;
		nTenLineColor = 0x656d78;
		nVolTitleColor = 0xaaaaaa;
    nUpFrameColor = 0xff0000;
    nUpFulllColor = 0x000000;
    nDownFullColor = 0x30ae0e;//0x36bc9b;
        
    frameColor = [HZCommonTool getThemeMinKlineSeprateColor];//
    scalesLineColor = [HZCommonTool getThemeMinKlineSeprateColor];
        nIndexsColor = 0xaaaaaa;
		//end
        
        pTimeLineArrayM = [[NSMutableArray alloc] init];
        pKLineMiddlePointArray = [[NSMutableArray alloc] init];
        
        pLandScapeBtn = [UIButton new];
        [pLandScapeBtn addTarget:self action:@selector(landscapeBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
        [pLandScapeBtn setImage:[UIImage imageNamed:@"landscape"] forState:UIControlStateNormal];
        [self addSubview:pLandScapeBtn];
        
        //添加长按手势
        UILongPressGestureRecognizer *pLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressOnClick:)];
        [self addGestureRecognizer:pLongPress];
    }
    return self;
}

- (void)longPressOnClick:(UILongPressGestureRecognizer *)press
{
    if (press.state == UIGestureRecognizerStateBegan) {
        if(!pKRes){
            return;
        }
        
        isShow10Line = !isShow10Line;
        [self show10LineWithLocation:[press locationInView:self]];
        isMoved = NO;
        if (nPosStart == pKRes->nKStartPos) {
            nSwipeLastPoint = CGPointZero;
        }
        if (nPosStart == (pKRes->nTotalCount+pKRes->nKStartPos - [self KLine_DrawMaxNumber])) {
            nSwipeLastPoint = CGPointMake(self.frame.size.width, 0);
        }
    }else if (press.state == UIGestureRecognizerStateChanged) {
        if (isShow10Line) {//十字线显示 滑动移动十字线
            [self show10LineWithLocation:[press locationInView:self]];
        }
    }else if (press.state == UIGestureRecognizerStateEnded) {
        isShow10Line = NO;
        [self setNeedsDisplay];
        [self.parent upToParentWithObjc:@(isShow10Line) withType:KMSClickIsShowTenLineActionType withParamter:[self p_packageMinPriceModel]];
    }
}

- (void)updateNewData
{
    bIsCalcStartPos = YES;
    [self setData:&g_pQuoteOper->KRes[0] withIndex:g_pQuoteOper->KIndex];
}

- (void)landscapeBtnOnClick
{
    [self.parent upToParentWithObjc:self withType:kHZ_setLandscapeScreen_Action withParamter:nil];
}
- (void)setLandScapeBtnHidden:(BOOL)hidden
{
    pLandScapeBtn.hidden = hidden;
    isLandscape = hidden;
}

-(void)setMTDistance:(int)n
{
	nMTDistance = n;
}

-(void)setLineExType:(int)n
{
	nLineExType = n;
	[self calcData];
}

-(void)setData:(QUOTELV_K_RES*)p withIndex:(QUOTELV_K_INDEX*)k
{
	pKRes = p;
	pKIndex = k;
    //计算区域
    [self calcRect];
	[self calcData];
    nPos = -1;
  
  if (!isLandscape) {// 横屏
    bIsCalcStartPos = YES;
  }
  
    [self setNeedsDisplay];
  
    nSwipeLastPoint = CGPointMake(self.frame.size.width, 0);
}

-(void)setColors:(NSArray*)aArray
{
	
	if ([aArray count] >= 11) {
    bgColor = stringToHex([aArray objectAtIndex:0]);
		nM5Color = stringToHex([aArray objectAtIndex:1]);
		nM10Color = stringToHex([aArray objectAtIndex:2]);
		nM20Color = stringToHex([aArray objectAtIndex:3]);
		nTenLineColor = stringToHex([aArray objectAtIndex:4]);
    nVolTitleColor = stringToHex([aArray objectAtIndex:5]);
		nUpFrameColor = stringToHex([aArray objectAtIndex:6]);
    nUpFulllColor = stringToHex([aArray objectAtIndex:7]);
    nDownFullColor = stringToHex([aArray objectAtIndex:8]);
    //边框颜色
    frameColor = stringToHex([aArray objectAtIndex:9]);
    scalesLineColor = stringToHex([aArray objectAtIndex:10]);
	}
	//
	if (pKRes) {
		if (nPos==-1) {
			[self movePos:nPosStart + [self KLine_DrawMaxNumber] - 1];
		}else {
			[self movePos:nPosStart + nPos];
		}
	}
	
	[self setNeedsDisplay];
}

- (BOOL)getTenLineStat
{
    return isShow10Line;
}

- (void)setTenLineState:(BOOL)isHidden
{
    isShow10Line = isHidden;
}

-(void)clear
{
	nPos = -1;
	bIsCalcStartPos = YES;
	pKRes = NULL;
	nLineExType = KLINE_EX_TYPE_VOL;
	[self setNeedsDisplay];
}

- (void)caculatorMothTimeLine
{
    [pTimeLineArrayM removeAllObjects];
    int nMaxCount = min(pKRes->nTotalCount+pKRes->nKStartPos, nPosStart+[self KLine_DrawMaxNumber]);
    for (int i = nPosStart; i < nMaxCount; i++) {
        int nDate = pKRes->kData[i].nDate;
        
        char temp[64];
        sprintf(temp, "%lld",DateTimeInt2Long(nDate));
        char dateBuf[8];
        char yearBuf[8];
        memset(dateBuf, 0, sizeof(dateBuf));
        memset(yearBuf, 0, sizeof(yearBuf));
        memcpy(dateBuf, temp, 6);
        memcpy(yearBuf, temp, 4);
        
        int nChinaDate = atoi(dateBuf);
        int nYear = atoi(yearBuf);
        int nMonth = nChinaDate%100;
        
        switch (pKRes->kLineType) {
            case QUOTELV_K_DATE:
            {
                if (i > nPosStart) {
                    NSArray *lastArray = [pTimeLineArrayM lastObject];
                    int nLastDate = [lastArray[1] intValue];
                    if (nChinaDate > nLastDate) {
                        NSMutableArray *array = [NSMutableArray array];
                        [array addObject:[NSNumber numberWithInt:i]];
                        [array addObject:[NSNumber numberWithInt:nChinaDate]];
                        [pTimeLineArrayM addObject:array];
                    }
                }else{
                    
                    NSMutableArray *array = [NSMutableArray array];
                    [array addObject:[NSNumber numberWithInt:i]];
                    [array addObject:[NSNumber numberWithInt:nChinaDate]];
                    [pTimeLineArrayM addObject:array];
                }
            }
                break;
            case QUOTELV_K_MONTH:
            {
                if (i > nPosStart) {
                    NSArray *lastArray = [pTimeLineArrayM lastObject];
                    int nLastDate = [lastArray[1] intValue];
                    if (nYear > nLastDate) {
                        NSMutableArray *array = [NSMutableArray array];
                        [array addObject:[NSNumber numberWithInt:i]];
                        [array addObject:[NSNumber numberWithInt:nYear]];
                        [pTimeLineArrayM addObject:array];
                    }
                }else{
                    
                    NSMutableArray *array = [NSMutableArray array];
                    [array addObject:[NSNumber numberWithInt:i]];
                    [array addObject:[NSNumber numberWithInt:nYear]];
                    [pTimeLineArrayM addObject:array];
                }
            }
                break;
            case QUOTELV_K_WEEK:
            {//取1月、5月、9月份的时间线
                
                if (i > nPosStart) {
                    NSArray *lastArray = [pTimeLineArrayM lastObject];
                    int nLastDate = [lastArray[1] intValue];
                    if ((nChinaDate > nLastDate) && (nMonth == 1 || nMonth == 5 || nMonth == 9)) {
                        NSMutableArray *array = [NSMutableArray array];
                        [array addObject:[NSNumber numberWithInt:i]];
                        [array addObject:[NSNumber numberWithInt:nChinaDate]];
                        [pTimeLineArrayM addObject:array];
                    }
                }else{
                    NSMutableArray *array = [NSMutableArray array];
                    [array addObject:[NSNumber numberWithInt:i]];
                    [array addObject:[NSNumber numberWithInt:nChinaDate]];
                    [pTimeLineArrayM addObject:array];
                }
            }
                break;
            default:
                break;
        }
    }
}

double calcSUM(double aPoint[], int aStartPos, int aCycle)
{
  int i = aStartPos - aCycle + 1;
  i  = i < 0 ? 0 : i;
  
  double nMax = 0;
  
  for (; i<=aStartPos; i++)
  {
    nMax += aPoint[i];
  }
  
  return nMax;
}

double calcCOUNT(QUOTELV_K_POINT* aPoint, int aStartPos, int aCycle)
{
  int i = aStartPos - aCycle + 1;
  i  = i < 1 ? 1 : i;
  
  double nCount = 0;
  
  for (; i<=aStartPos; i++)
  {
    if (aPoint[i].fCur > aPoint[i-1].fCur) {
      nCount++;
    }
  }
  
  return nCount;
}

double calcMA(QUOTELV_K_POINT* aPoint, int aStartPos, int aCycle)
{
  int i = aStartPos - aCycle + 1;
  double ma = 0;
  double nMax = 0;
  
  if (i < 0)
  {
    return ma;
  }
  
  for (; i<=aStartPos; i++)
  {
    nMax += aPoint[i].fCur;
  }
  
  ma = nMax/aCycle;
  
  return ma;
}

-(void)calcData
{
	/*price*/
	float fMaxPrice;
	float fMinPrice;
	/*kdj*/
	float fMaxKDJ;
	float fMinKDJ;
	/*rsi*/
	float fMaxRSI;
	float fMinRSI;
	/*MACD*/
	float fMaxMACD;
	float fMinMACD;
	float fMaxBSS;
	float fMinBSS;
	/*WR*/
	float fMaxWR;
	float fMinWR;
	/*BIAS*/
	float fMaxBIAS;
	float fMinBIAS;
	/*ARBR*/
	float fMaxARBR;
	float fMinARBR;
	/*CCI*/
	float fMaxCCI;
	float fMinCCI;
	
	/*DMA*/
	float fMaxDMA;
	float fMinDMA;
	
	/*PSY*/
	float fMaxPSY;
	float fMinPSY;
	
	/*BOLL*/
	float fMaxBOLL;
	float fMinBOLL;
	
	/*vol*/
	long64 lMaxVolume;
  
  //lisz add 20110916 start
  float fMaxDDX;
  float fMinDDX;
  long64 fMaxBBD;
  long64 fMinBBD;
  //lisz add 20110916 end
	
	if (!pKRes) {
		return;
	}
	//计算均线
    [MAModifyView readConfigData];
	QuoteLvKIndex_calcPriceAVG(pKIndex, pKRes);
	
	if (pKRes->nTotalCount<=0) {
		return;
	}
    
	if (bIsCalcStartPos) {
		nPosStart = pKRes->nTotalCount - [self KLine_DrawMaxNumber];
		nPosStart = nPosStart+pKRes->nKStartPos;
		if(nPosStart<pKRes->nKStartPos)
		{
			nPosStart = pKRes->nKStartPos;
		}
		bIsCalcStartPos = NO;
	}
	//新版
	if (nPos==-1) {
		[self movePos:nPosStart + [self KLine_DrawMaxNumber] - 1];
	}
	//end
  
    
    //计算每月时间线
//    [self caculatorMothTimeLine];
  
	
	//最大，小价，最大量
	if (pKRes->nTotalCount >0)
	{
		/*price*/
		fMaxPrice = pKRes->kData[nPosStart].fHigh;
		fMinPrice = pKRes->kData[nPosStart].fLow;
		
		//取均价最大，最小
		fMaxPrice = max(fMaxPrice, pKIndex->PAVG.M5[nPosStart]);
		fMaxPrice = max(fMaxPrice, pKIndex->PAVG.M10[nPosStart]);
		fMaxPrice = max(fMaxPrice, pKIndex->PAVG.M20[nPosStart]);
        fMaxPrice = max(fMaxPrice, pKIndex->PAVG.M60[nPosStart]);
		
		fMinPrice = minz(fMinPrice, pKIndex->PAVG.M5[nPosStart]);
		fMinPrice = minz(fMinPrice, pKIndex->PAVG.M10[nPosStart]);
		fMinPrice = minz(fMinPrice, pKIndex->PAVG.M20[nPosStart]);
        fMinPrice = minz(fMinPrice, pKIndex->PAVG.M60[nPosStart]);
        
		
		/*vol*/
		lMaxVolume = pKRes->kData[nPosStart].lVol;
	}
	
	if (lMaxVolume<3)
	{
		lMaxVolume = 3;
	}
	
	int nMaxCount;
	nMaxCount = min(pKRes->nTotalCount+pKRes->nKStartPos, nPosStart+[self KLine_DrawMaxNumber]);
	
	//价
	for(int i=nPosStart; i<nMaxCount; i++)
	{
		//最高
		
		fMaxPrice = max(fMaxPrice, pKRes->kData[i].fHigh);
		fMinPrice = min(fMinPrice, pKRes->kData[i].fLow);
		
		//取均价最大，最小
		fMaxPrice = max(fMaxPrice, pKIndex->PAVG.M5[i]);
		fMaxPrice = max(fMaxPrice, pKIndex->PAVG.M10[i]);
		fMaxPrice = max(fMaxPrice, pKIndex->PAVG.M20[i]);
        fMaxPrice = max(fMaxPrice, pKIndex->PAVG.M60[i]);
		
		fMinPrice = minz(fMinPrice, pKIndex->PAVG.M5[i]);
		fMinPrice = minz(fMinPrice, pKIndex->PAVG.M10[i]);
		fMinPrice = minz(fMinPrice, pKIndex->PAVG.M20[i]);
        fMinPrice = minz(fMinPrice, pKIndex->PAVG.M60[i]);
	}
	
//	for (int i=pKIndex->nPAVGPos; i<nMaxCount; i++) {
//		//取均价最大，最小
//		fMaxPrice = max(fMaxPrice, pKIndex->PAVG.M5[pKIndex->PAVG_N1+i]);
//		fMaxPrice = max(fMaxPrice, pKIndex->PAVG.M10[pKIndex->PAVG_N2+i]);
//		fMaxPrice = max(fMaxPrice, pKIndex->PAVG.M20[pKIndex->PAVG_N3+i]);
//		
//		fMinPrice = minz(fMinPrice, pKIndex->PAVG.M5[pKIndex->PAVG_N1+i]);
//		fMinPrice = minz(fMinPrice, pKIndex->PAVG.M10[pKIndex->PAVG_N1+i]);
//		fMinPrice = minz(fMinPrice, pKIndex->PAVG.M20[pKIndex->PAVG_N1+i]);
//	}
	
    if (n_Mode == KLINE_MODE_SPECIAL) {
        //计算vol
        for(int i=nPosStart; i<nMaxCount; i++) {
            lMaxVolume = max(lMaxVolume, pKRes->kData[i].lVol);
        }
        lScalesVolume[0] = lMaxVolume;
        lScalesVolume[1] = lMaxVolume/2;
        lScalesVolume[2] = 0;
    }
	switch (nLineExType) {
		case KLINE_EX_TYPE_KDJ:
		{
			QuoteLvKIndex_calcKDJ(pKIndex, pKRes);
			
			//kdj
			fMaxKDJ = pKIndex->KDJ.K[nPosStart];
			fMaxKDJ = max(fMaxKDJ, pKIndex->KDJ.D[nPosStart]);
			fMaxKDJ = max(fMaxKDJ, pKIndex->KDJ.J[nPosStart]);
			fMinKDJ = pKIndex->KDJ.K[nPosStart];
			fMinKDJ = min(fMinKDJ, pKIndex->KDJ.D[nPosStart]);
			fMinKDJ = min(fMinKDJ, pKIndex->KDJ.J[nPosStart]);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//kdj
				fMaxKDJ = max(fMaxKDJ, pKIndex->KDJ.K[i]);
				fMaxKDJ = max(fMaxKDJ, pKIndex->KDJ.D[i]);
				fMaxKDJ = max(fMaxKDJ, pKIndex->KDJ.J[i]);
				fMinKDJ = min(fMinKDJ, pKIndex->KDJ.K[i]);
				fMinKDJ = min(fMinKDJ, pKIndex->KDJ.D[i]);
				fMinKDJ = min(fMinKDJ, pKIndex->KDJ.J[i]);
			}
			//修正KDJ值
			fMaxKDJ = min(fMaxKDJ, 100);
			fMinKDJ = max(fMinKDJ, 0);
            
      if(fMaxKDJ==fMinKDJ)
      {
          fMaxKDJ = 100;
          fMinKDJ = 0;
      }
      
		}
			break;
		case KLINE_EX_TYPE_RSI:
		{
			QuoteLvKIndex_calcRSI(pKIndex, pKRes);
			//rsi
			fMaxRSI = pKIndex->RSI.RSI1[nPosStart];
			fMaxRSI = max(fMaxRSI, pKIndex->RSI.RSI2[nPosStart]);
			fMaxRSI = max(fMaxRSI, pKIndex->RSI.RSI3[nPosStart]);
			fMinRSI = pKIndex->RSI.RSI1[nPosStart];
			fMinRSI = minz(fMinRSI, pKIndex->RSI.RSI2[nPosStart]);
			fMinRSI = minz(fMinRSI, pKIndex->RSI.RSI3[nPosStart]);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//rsi
				fMaxRSI = max(fMaxRSI, pKIndex->RSI.RSI1[i]);
				fMaxRSI = max(fMaxRSI, pKIndex->RSI.RSI2[i]);
				fMaxRSI = max(fMaxRSI, pKIndex->RSI.RSI3[i]);
				fMinRSI = minz(fMinRSI, pKIndex->RSI.RSI1[i]);
				fMinRSI = minz(fMinRSI, pKIndex->RSI.RSI2[i]);
				fMinRSI = minz(fMinRSI, pKIndex->RSI.RSI3[i]);
			}
			
			fScalesRSI[0] = fMaxRSI;
			fScalesRSI[1] = (fMaxRSI-fMinRSI)/2+fMinRSI;
			fScalesRSI[2] = fMinRSI;
		}
			break;
		case KLINE_EX_TYPE_MACD:
		{
			QuoteLvKIndex_calcMACD(pKIndex, pKRes);
            
            fMaxMACD = 0.0;
            fMinMACD = 0.0;
			//macd
			fMaxMACD = pKIndex->MACD.DIF[nPosStart];// pKData->kPoint[nPosStart].fDIF;
			fMaxMACD = max(fMaxMACD, pKIndex->MACD.DEA[nPosStart]);
			fMinMACD = pKIndex->MACD.DIF[nPosStart];
			fMinMACD = min(fMinMACD, pKIndex->MACD.DEA[nPosStart]);
			
			
			fMaxBSS = (pKIndex->MACD.DIF[nPosStart] - pKIndex->MACD.DEA[nPosStart]);
			fMinBSS = fMaxBSS;
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//macd
				fMaxMACD = max(fMaxMACD, pKIndex->MACD.DIF[i]);
			  fMaxMACD = max(fMaxMACD, pKIndex->MACD.DEA[i]);
			  fMaxMACD = max(fMaxMACD, pKIndex->MACD.MACD[i]);
			  fMinMACD = min(fMinMACD, pKIndex->MACD.DIF[i]);
			  fMinMACD = min(fMinMACD, pKIndex->MACD.DEA[i]);
			  fMinMACD = min(fMinMACD, pKIndex->MACD.MACD[i]);
			}
      fScalesMACD[0] = fMaxMACD;
			fScalesMACD[1] = (fMaxMACD-fMinMACD)/2+fMinMACD;
			fScalesMACD[2] = fMinMACD;
		}
			break;
		case KLINE_EX_TYPE_WR:
		{
			QuoteLvKIndex_calcWR(pKIndex, pKRes);
			fMaxWR = pKIndex->WR.WR1[nPosStart];
			fMaxWR = max(fMaxWR,pKIndex->WR.WR2[nPosStart]);
			fMinWR = pKIndex->WR.WR1[nPosStart];
			fMinWR = min(fMinWR,pKIndex->WR.WR2[nPosStart]);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//wr
				fMaxWR = max(fMaxWR,pKIndex->WR.WR1[i]);
				fMaxWR = max(fMaxWR,pKIndex->WR.WR2[i]);
				fMinWR = min(fMinWR,pKIndex->WR.WR1[i]);
				fMinWR = min(fMinWR,pKIndex->WR.WR2[i]);
			}
			
			fScalesWR[0] = fMaxWR;
			fScalesWR[1] = (fMaxWR+fMinWR)/2;
			fScalesWR[2] = fMinWR;
		
		}
			break;
		case KLINE_EX_TYPE_BIAS:
		{
//			QuoteLvKIndex_calcBIAS(pKIndex, pKRes);
      pKIndex->BIAS_L1 = 6;
      pKIndex->BIAS_L2 = 12;
      pKIndex->BIAS_L3 = 24;
 
      int MaxCycle = pKIndex->BIAS_L1 > pKIndex->BIAS_L2 ? pKIndex->BIAS_L1 : pKIndex->BIAS_L2;
      MaxCycle = MaxCycle > pKIndex->BIAS_L3 ? MaxCycle : pKIndex->BIAS_L3;
      int sPos = pKRes->nMaxCount - pKRes->nTotalCount - MaxCycle;		//起始位置
      sPos = sPos > 0 ? sPos : 0;
      
      int i = 0;
      double AVGL1[KLIN_MAX_NUM];
      double AVGL2[KLIN_MAX_NUM];
      double AVGL3[KLIN_MAX_NUM];
      
      for (i = sPos; i<pKRes->nMaxCount; i++) {
        AVGL1[i] = calcMA(pKRes->kData, i, pKIndex->BIAS_L1);
        AVGL2[i] = calcMA(pKRes->kData, i, pKIndex->BIAS_L2);
        AVGL3[i] = calcMA(pKRes->kData, i, pKIndex->BIAS_L3);
      }
      
      sPos = pKRes->nMaxCount - pKRes->nTotalCount;
      
      //lisz add 判断0时的情况
      for (i = sPos; i<pKRes->nMaxCount; i++) {
        if(AVGL1[i]!=0)
        {
          pKIndex->BIAS.BIAS1[i] = ((pKRes->kData[i].fCur - AVGL1[i])/AVGL1[i])*100;
        }
        else
        {
          pKIndex->BIAS.BIAS1[i] = 0;
        }
        if(AVGL2[i]!=0)
        {
          pKIndex->BIAS.BIAS2[i] = ((pKRes->kData[i].fCur - AVGL2[i])/AVGL2[i])*100;
        }
        else
        {
          pKIndex->BIAS.BIAS2[i] = 0;
        }
        
        if(AVGL3[i]!=0)
        {
          pKIndex->BIAS.BIAS3[i] = ((pKRes->kData[i].fCur - AVGL3[i])/AVGL3[i])*100;
        }
        else
        {
          pKIndex->BIAS.BIAS3[i] = 0;
        }
      }
      //////////////////
      fMaxBIAS = pKIndex->BIAS.BIAS1[nPosStart];
			fMaxBIAS = max(fMaxBIAS,pKIndex->BIAS.BIAS2[nPosStart]);
			fMaxBIAS = max(fMaxBIAS,pKIndex->BIAS.BIAS3[nPosStart]);
			fMinBIAS = pKIndex->BIAS.BIAS1[nPosStart];
			fMinBIAS = min(fMinBIAS,pKIndex->BIAS.BIAS2[nPosStart]);
			fMinBIAS = min(fMinBIAS,pKIndex->BIAS.BIAS3[nPosStart]);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//BIAS
				fMaxBIAS = max(fMaxBIAS,pKIndex->BIAS.BIAS1[i]);
				fMaxBIAS = max(fMaxBIAS,pKIndex->BIAS.BIAS2[i]);
				fMaxBIAS = max(fMaxBIAS,pKIndex->BIAS.BIAS3[i]);
				fMinBIAS = min(fMinBIAS,pKIndex->BIAS.BIAS1[i]);
				fMinBIAS = min(fMinBIAS,pKIndex->BIAS.BIAS2[i]);
				fMinBIAS = min(fMinBIAS,pKIndex->BIAS.BIAS3[i]);

			}
			
			fScalesBIAS[0] = fMaxBIAS;
			fScalesBIAS[1] = (fMaxBIAS-fMinBIAS)/2;
			fScalesBIAS[2] = fMinBIAS;
			
		}
			break;
		case KLINE_EX_TYPE_DMA:
		{
			QuoteLvKIndex_calcDMA(pKIndex, pKRes);
			fMaxDMA = pKIndex->DMA.DDD[nPosStart];
			fMaxDMA = max(fMaxDMA,pKIndex->DMA.AMA[nPosStart]);
			fMinDMA = pKIndex->DMA.DDD[nPosStart];
			fMinDMA = min(fMinDMA,pKIndex->DMA.AMA[nPosStart]);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//wr
				fMaxDMA = max(fMaxDMA,pKIndex->DMA.DDD[i]);
				fMaxDMA = max(fMaxDMA,pKIndex->DMA.AMA[i]);
				fMinDMA = min(fMinDMA,pKIndex->DMA.DDD[i]);
				fMinDMA = min(fMinDMA,pKIndex->DMA.AMA[i]);
			}
			
			fScalesDMA[0] = fMaxDMA;
			fScalesDMA[1] = (fMaxDMA-fMinDMA)/2;
			fScalesDMA[2] = fMinDMA;
			
		}
			break;
		case KLINE_EX_TYPE_ARBR:
		{
//			QuoteLvKIndex_calcARBR(pKIndex, pKRes);
      int sPos = pKRes->nMaxCount - pKRes->nTotalCount - pKIndex->ARBR_N;		//起始位置
      sPos = sPos > 0 ? sPos : 0;
      
      int i = 0;
      double SUM1[KLIN_MAX_NUM];
      double SUM2[KLIN_MAX_NUM];
      double MAX1[KLIN_MAX_NUM];
      double MAX2[KLIN_MAX_NUM];
      double MAX3[KLIN_MAX_NUM];
      double MAX4[KLIN_MAX_NUM];
      double SUM3[KLIN_MAX_NUM];
      double SUM4[KLIN_MAX_NUM];
      
      for (i = sPos; i<pKRes->nMaxCount; i++) {
        MAX1[i] = pKRes->kData[i].fHigh - pKRes->kData[i].fOpen;
        MAX2[i] = pKRes->kData[i].fOpen - pKRes->kData[i].fLow;
        MAX3[i] = max(0,pKRes->kData[i].fHigh - pKRes->kData[i-1<0?0:i-1].fCur);
        MAX4[i] = max(0,pKRes->kData[i-1<0?0:i-1].fCur - pKRes->kData[i].fLow);
      }
      
      for (i = sPos; i<pKRes->nMaxCount; i++) {
        SUM1[i] = calcSUM(MAX1, i, pKIndex->ARBR_N);
        SUM2[i] = calcSUM(MAX2, i, pKIndex->ARBR_N);
        SUM3[i] = calcSUM(MAX3, i, pKIndex->ARBR_N);
        SUM4[i] = calcSUM(MAX4, i, pKIndex->ARBR_N);
      }
      
      sPos = pKRes->nMaxCount - pKRes->nTotalCount;
      
      for (i = sPos; i<pKRes->nMaxCount; i++) {
        //add by jason 20111103 修改算法和android相同
        if(SUM1[i]!=0 && SUM2[i]!=0)
        {
          pKIndex->ARBR.AR[i] = (SUM1[i]/SUM2[i])*100;
        }
        else
        {
          pKIndex->ARBR.AR[i] = 0;
        }
        if(SUM3[i]!=0 && SUM4[i]!=0)
        {
          pKIndex->ARBR.BR[i] = (SUM3[i]/SUM4[i])*100;
        }
        else
        {
          pKIndex->ARBR.BR[i] = 0;
        }
        //		 aKIndex->ARBR.AR[i] = (SUM1[i]/SUM2[i])*100;
        //		 aKIndex->ARBR.BR[i] = (SUM3[i]/SUM4[i])*100;
        
      }
/////////////////////
      
      fMaxARBR = pKIndex->ARBR.AR[nPosStart];
      fMaxARBR = max(fMaxARBR,pKIndex->ARBR.BR[nPosStart]);
			fMinARBR = pKIndex->ARBR.AR[nPosStart];
			fMinARBR = minz(fMinARBR,pKIndex->ARBR.BR[nPosStart]);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//wr
				fMaxARBR = max(fMaxARBR,pKIndex->ARBR.AR[i]);
				fMaxARBR = max(fMaxARBR,pKIndex->ARBR.BR[i]);
				fMinARBR = minz(fMinARBR,pKIndex->ARBR.AR[i]);
				fMinARBR = minz(fMinARBR,pKIndex->ARBR.BR[i]);
			}
			
			fScalesARBR[0] = fMaxARBR;
			fScalesARBR[1] = (fMaxARBR-fMinARBR)/2;
			fScalesARBR[2] = fMinARBR;
			
		}
			break;
		case KLINE_EX_TYPE_CCI:
		{
			QuoteLvKIndex_calcCCI(pKIndex, pKRes);
			fMaxCCI = pKIndex->CCI.CCI[nPosStart];
			fMinCCI = pKIndex->CCI.CCI[nPosStart];
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//wr
				fMaxCCI = max(fMaxCCI,pKIndex->CCI.CCI[i]);
				fMinCCI = min(fMinCCI,pKIndex->CCI.CCI[i]);
			}
			
			fScalesCCI[0] = fMaxCCI;
			fScalesCCI[1] = fMinCCI + abs((fMaxCCI-fMinCCI)/2);
			fScalesCCI[2] = fMinCCI;
			
		}
			break;
		case KLINE_EX_TYPE_PSY:
		{
//			QuoteLvKIndex_calcPSY(pKIndex, pKRes);
      
//////////////
      pKIndex->PSY_N = 12;
      int sPos = pKRes->nMaxCount - pKRes->nTotalCount - pKIndex->PSY_N;		//起始位置
      sPos = sPos > 0 ? sPos : 0;
      
      int i = 0;
      double COUNT[KLIN_MAX_NUM];
      
      for (i = sPos; i<pKRes->nMaxCount; i++) {
        COUNT[i] = calcCOUNT(pKRes->kData,i,pKIndex->PSY_N);
      }
      
      sPos = pKRes->nMaxCount - pKRes->nTotalCount;
      
      for (i = sPos; i<pKRes->nMaxCount; i++) {
        pKIndex->PSY.PSY[i] = COUNT[i]/pKIndex->PSY_N*100;
      }
///////////
      
      fMaxPSY = pKIndex->PSY.PSY[nPosStart];
			fMinPSY = pKIndex->PSY.PSY[nPosStart];
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//wr
				fMaxPSY = max(fMaxPSY,pKIndex->PSY.PSY[i]);
				fMinPSY = min(fMinPSY,pKIndex->PSY.PSY[i]);
			}
			
			fScalesPSY[0] = fMaxPSY;
			fScalesPSY[1] = fMinPSY+abs((fMaxPSY-fMinPSY)/2);
			fScalesPSY[2] = fMinPSY;
			
		}
			break;
		case KLINE_EX_TYPE_BOLL:
		{
			QuoteLvKIndex_calcBOLL(pKIndex, pKRes);
			fMaxBOLL = pKIndex->BOLL.MID[nPosStart];
			fMaxBOLL = max(fMaxBOLL,pKIndex->BOLL.UPPER[nPosStart]);
			fMaxBOLL = max(fMaxBOLL,pKIndex->BOLL.LOWER[nPosStart]);
			fMinBOLL = pKIndex->BOLL.MID[nPosStart];
			fMinBOLL = min(fMinBOLL,pKIndex->BOLL.UPPER[nPosStart]);
			fMinBOLL = min(fMinBOLL,pKIndex->BOLL.LOWER[nPosStart]);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//BIAS
				fMaxBOLL = max(fMaxBOLL,pKIndex->BOLL.MID[i]);
				fMaxBOLL = max(fMaxBOLL,pKIndex->BOLL.UPPER[i]);
				fMaxBOLL = max(fMaxBOLL,pKIndex->BOLL.LOWER[i]);
				fMinBOLL = min(fMinBOLL,pKIndex->BOLL.MID[i]);
				fMinBOLL = min(fMinBOLL,pKIndex->BOLL.UPPER[i]);
				fMinBOLL = min(fMinBOLL,pKIndex->BOLL.LOWER[i]);
				
			}
			
			fMaxBOLL = fMaxBOLL > fMaxPrice ? fMaxBOLL : fMaxPrice;
			fMinBOLL = fMinBOLL < fMinPrice ? fMinBOLL : fMinPrice;
			fScalesBOLL[0] = fMaxBOLL;
			fScalesBOLL[1] = (fMaxBOLL+fMinBOLL)/2;
			fScalesBOLL[2] = fMinBOLL;
			
		}
			break;
      //lisz add 20110916 start
    case KLINE_EX_TYPE_DDX:
    {
      QuoteLvKIndex_calcDDX(pKIndex, pKRes);
      
      
      fMaxDDX = pKIndex->DDX.ddx[nPosStart];
			fMaxDDX = max(fMaxDDX,pKIndex->DDX.ddx1[nPosStart]);
			fMaxDDX = max(fMaxDDX,pKIndex->DDX.ddx2[nPosStart]);
      fMaxDDX = max(fMaxDDX,pKIndex->DDX.ddx3[nPosStart]);
      
			fMinDDX = pKIndex->DDX.ddx[nPosStart];
			fMinDDX = min(fMinDDX,pKIndex->DDX.ddx1[nPosStart]);
			fMinDDX = min(fMinDDX,pKIndex->DDX.ddx2[nPosStart]);
      fMinDDX = min(fMinDDX,pKIndex->DDX.ddx3[nPosStart]);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//DDX
        fMaxDDX = max(fMaxDDX,pKIndex->DDX.ddx[i]);
        fMaxDDX = max(fMaxDDX,pKIndex->DDX.ddx1[i]);
        fMaxDDX = max(fMaxDDX,pKIndex->DDX.ddx2[i]);
        fMaxDDX = max(fMaxDDX,pKIndex->DDX.ddx3[i]);
        
        fMinDDX = min(fMinDDX,pKIndex->DDX.ddx[i]);
        fMinDDX = min(fMinDDX,pKIndex->DDX.ddx1[i]);
        fMinDDX = min(fMinDDX,pKIndex->DDX.ddx2[i]);
        fMinDDX = min(fMinDDX,pKIndex->DDX.ddx3[i]);
			}
      
      fScalesDDX[0] = fMaxDDX;
			fScalesDDX[1] = (fMaxDDX+fMinDDX)/2;
			fScalesDDX[2] = fMinDDX;
    }
      break;
    case KLINE_EX_TYPE_DDY:
    {
      QuoteLvKIndex_calcDDY(pKIndex, pKRes);
      
      //为了少用空间，使用DDX中的变量存储值
      fMaxDDX = pKIndex->DDY.ddy[nPosStart];
			fMaxDDX = max(fMaxDDX,pKIndex->DDY.ddy1[nPosStart]);
			fMaxDDX = max(fMaxDDX,pKIndex->DDY.ddy2[nPosStart]);
      fMaxDDX = max(fMaxDDX,pKIndex->DDY.ddy3[nPosStart]);
      
			fMinDDX = pKIndex->DDY.ddy[nPosStart];
			fMinDDX = min(fMinDDX,pKIndex->DDY.ddy1[nPosStart]);
			fMinDDX = min(fMinDDX,pKIndex->DDY.ddy2[nPosStart]);
      fMinDDX = min(fMinDDX,pKIndex->DDY.ddy3[nPosStart]);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//DDX
        fMaxDDX = max(fMaxDDX,pKIndex->DDY.ddy[i]);
        fMaxDDX = max(fMaxDDX,pKIndex->DDY.ddy1[i]);
        fMaxDDX = max(fMaxDDX,pKIndex->DDY.ddy2[i]);
        fMaxDDX = max(fMaxDDX,pKIndex->DDY.ddy3[i]);
        
        fMinDDX = min(fMinDDX,pKIndex->DDY.ddy[i]);
        fMinDDX = min(fMinDDX,pKIndex->DDY.ddy1[i]);
        fMinDDX = min(fMinDDX,pKIndex->DDY.ddy2[i]);
        fMinDDX = min(fMinDDX,pKIndex->DDY.ddy3[i]);
			}
      
      fScalesDDX[0] = fMaxDDX;
			fScalesDDX[1] = (fMaxDDX+fMinDDX)/2;
			fScalesDDX[2] = fMinDDX;
    }
      break;
    case KLINE_EX_TYPE_DDZ:
    {
      QuoteLvKIndex_calcDDZ(pKIndex, pKRes);
      
      //为了少用空间，使用DDX中的变量存储值
      fMaxDDX = pKIndex->DDZ.ddz[nPosStart];
			fMinDDX = pKIndex->DDZ.ddz[nPosStart];
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//DDZ
        fMaxDDX = max(fMaxDDX,pKIndex->DDZ.ddz[i]);
        fMinDDX = min(fMinDDX,pKIndex->DDZ.ddz[i]);
			}
      
      fScalesDDX[0] = fMaxDDX;
			fScalesDDX[1] = (fMaxDDX+fMinDDX)/2;
			fScalesDDX[2] = fMinDDX;
    }
      break;
    case KLINE_EX_TYPE_BBD_RETAI:
    {
      QuoteLvKIndex_calcBBDRetai(pKIndex, pKRes);
      
      //为了少用空间，使用DDX中的变量存储值
      fMaxDDX = pKIndex->BBDRetai.shareholdingRatio[nPosStart];
			fMinDDX = pKIndex->BBDRetai.shareholdingRatio[nPosStart];
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//DDZ
        fMaxDDX = max(fMaxDDX, pKIndex->BBDRetai.shareholdingRatio[i]);
        fMinDDX = min(fMinDDX, pKIndex->BBDRetai.shareholdingRatio[i]);
			}
      
      fScalesDDX[0] = fMaxDDX;
			fScalesDDX[1] = (fMaxDDX+fMinDDX)/2;
			fScalesDDX[2] = fMinDDX;
    }
      break;
    case KLINE_EX_TYPE_BBD_MAIN:
    {
      QuoteLvKIndex_calcBBDMain(pKIndex, pKRes);
      
      //为了少用空间，使用DDX中的变量存储值
      fMaxDDX = pKIndex->BBDMain.shareholdingRatio[nPosStart];
			fMinDDX = pKIndex->BBDMain.shareholdingRatio[nPosStart];
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//DDZ
        fMaxDDX = max(fMaxDDX, pKIndex->BBDMain.shareholdingRatio[i]);
        fMinDDX = min(fMinDDX, pKIndex->BBDMain.shareholdingRatio[i]);
			}
      
      fScalesDDX[0] = fMaxDDX;
			fScalesDDX[1] = (fMaxDDX+fMinDDX)/2;
			fScalesDDX[2] = fMinDDX;
    }
      break;
    case KLINE_EX_TYPE_BBD:
    {
      QuoteLvKIndex_calcBBD(pKIndex, pKRes);
      
      //为了少用空间，使用DDX中的变量存储值
      fMaxBBD = pKIndex->BBD.bbd[nPosStart];
			fMaxBBD = max(fMaxBBD, pKIndex->BBD.sum1[nPosStart]);
			fMaxBBD = max(fMaxBBD, pKIndex->BBD.sum2[nPosStart]);
      fMaxBBD = max(fMaxBBD, pKIndex->BBD.sum3[nPosStart]);
      
			fMinBBD = pKIndex->BBD.bbd[nPosStart];
			fMinBBD = min(fMinBBD, pKIndex->BBD.sum1[nPosStart]);
			fMinBBD = min(fMinBBD, pKIndex->BBD.sum2[nPosStart]);
      fMinBBD = min(fMinBBD, pKIndex->BBD.sum3[nPosStart]);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//DDX
        fMaxBBD = max(fMaxBBD, pKIndex->BBD.bbd[i]);
        fMaxBBD = max(fMaxBBD, pKIndex->BBD.sum1[i]);
        fMaxBBD = max(fMaxBBD, pKIndex->BBD.sum2[i]);
        fMaxBBD = max(fMaxBBD, pKIndex->BBD.sum3[i]);
        
        fMinBBD = min(fMinBBD, pKIndex->BBD.bbd[i]);
        fMinBBD = min(fMinBBD, pKIndex->BBD.sum1[i]);
        fMinBBD = min(fMinBBD, pKIndex->BBD.sum2[i]);
        fMinBBD = min(fMinBBD, pKIndex->BBD.sum3[i]);
			}
      
      fScalesDDX[0] = fMaxBBD;
			fScalesDDX[1] = (fMaxBBD+fMinBBD)/2;
			fScalesDDX[2] = fMinBBD;
    }
      break;
    case KLINE_EX_TYPE_AVG_VOL_SUM:
    {
      QuoteLvKIndex_calcAvgVolSum(pKIndex, pKRes);
      
      //为了少用空间，使用DDX中的变量存储值
      fMaxDDX = pKIndex->AVG_VOL_SUM.avgSum[nPosStart];
	  
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				//avg sum
        fMaxDDX = max(fMaxDDX, pKIndex->AVG_VOL_SUM.avgSum[i]);
			}
      
      fScalesDDX[0] = fMaxDDX;
			fScalesDDX[1] = fMaxDDX/2;
			fScalesDDX[2] = 0;
    }
      break;
      //lisz add 20110916 end
		case KLINE_EX_TYPE_VOL://量
		default:
		{
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				lMaxVolume = max(lMaxVolume, pKRes->kData[i].lVol);
			}
			lScalesVolume[0] = lMaxVolume;
			lScalesVolume[1] = lMaxVolume/2;
			lScalesVolume[2] = 0;
		}
			break;
	}
	
	//价刻度
	float MM = fMaxPrice - fMinPrice;
    MM = fMaxPrice - fMinPrice;
	float fMaxDiff = MM;
	float fMinDiff = ((float)KVIEW_PRICE_SCALES_NUM)/(pow(10,pKRes->codeinfo.decNum));
	if (fMaxDiff < fMinDiff) {
		MM = fMinDiff;
		fMinPrice = fMaxPrice - fMinDiff;
	}
	
	fScalesPrice[0] = fMaxPrice;
	int count = KVIEW_PRICE_SCALES_NUM - 1;
	for(int i=1; i<=count; i++) {
		fScalesPrice[i] = fMaxPrice - MM*i/count;
	}
	
	fScalesPrice[KVIEW_PRICE_SCALES_NUM - 1] = fMinPrice;
	//
	pMax = fMaxPrice;
	pMin = fMinPrice;
	//
	
	int w,h;
	w = self.frame.size.width-2;
	h = nPriceHeight-2;//nHight*2-2-TITLE_HEIGHT-VOL_TITLE_HEIGHT;
	
	int x0,y0,x1,y1;
	
	int nKMaxNum = [self KLine_DrawMaxNumber];
	int w2;
	
	x0 =  LEFT_WIDTH(isLandscape) + 1;
	w2 = (nKLineWidth-1)>>1;
	//w2++;
	
	int np = 0;
	int nULen;
	int nDLen;
	nUpLen=0;
	nDownLen = 0;
	GUI_RECT r;
	//lisz 20091106 修改Ｋ线均价问题。
	{
		int nSize;
		nSize = sizeof(GUI_POINT)*nKMaxNum;
		memset(pLine5, 0, nSize);
		memset(pLine10, 0, nSize);
		memset(pLine20, 0, nSize);
        memset(pLine60, 0, nSize);
	}
	
	GUI_RECT rectPrice;
	GUI_RECT rectVol;
	rectPrice.nLeft = self.frame.origin.x+LEFT_WIDTH(isLandscape);
	rectPrice.nRight = rectPrice.nLeft+(self.frame.size.width-LEFT_WIDTH(isLandscape) - RIGHT_WIDTH(isLandscape))-1;
	rectPrice.nTop = nPriceTop+1;
	rectPrice.nBottom = nPriceTop+nPriceHeight;
	rectVol = rectPrice;
	rectVol.nTop = nVolTop+1;
	rectVol.nBottom = nVolTop+nVolHeight;
    
	nULen = nDLen = 0;
	
  if (MM==0) {
    MM=0;
  } else {
    MM = h/MM;
  }
	
	//价
    [pKLineMiddlePointArray removeAllObjects];
	for(int i=nPosStart; i<nMaxCount; i++)
	{
		x0+=SA_WIDTH;
		x1 = x0 + w2;
        
    [pKLineMiddlePointArray addObject:[NSNumber numberWithInt:x1]];
		
		//最高最低
		y0 = rectPrice.nTop + (fMaxPrice - pKRes->kData[i].fHigh)*MM;
		y1 = rectPrice.nTop + (fMaxPrice - pKRes->kData[i].fLow)*MM;
		
		//add by jason 增加开盘涨跌停的特殊处理        
		int nflag = [self isUpOrDown:i];//涨跌标志
		//end
		
		//蜡烛图，成交量
		if(nflag == 1)
		{
			r.nLeft = x0;
			r.nRight = x0+nKLineWidth;
			r.nTop = rectPrice.nTop + (fMaxPrice - pKRes->kData[i].fCur)*MM;
			r.nBottom = rectPrice.nTop + (fMaxPrice - pKRes->kData[i].fOpen)*MM;
			r.nBottom = (r.nBottom == r.nTop) ? r.nTop + 1 : r.nBottom;
			
			pRectUp[nULen] = r;
			pUp[nULen].x = x1;//(nKLineWidth)/2;
			pUp[nULen].yHight = y0;
			pUp[nULen].yLow = y1;
			
			nULen++;
		}
		else
 		{
			r.nLeft = x0;
			r.nRight = x0+nKLineWidth;
			r.nTop = rectPrice.nTop + (fMaxPrice - pKRes->kData[i].fOpen)*MM;
			r.nBottom = rectPrice.nTop  + (fMaxPrice - pKRes->kData[i].fCur)*MM;
			r.nBottom = (r.nBottom == r.nTop) ? r.nTop + 1 : r.nBottom;
			
			pRectDown[nDLen] = r;
			pDown[nDLen].x = x1;//(nKLineWidth)/2;
			pDown[nDLen].yHight = y0;
			pDown[nDLen].yLow = y1;
			
			nDLen++;
		}
		
		//均价5
		if (pKIndex->PAVG.M5[i] !=0)
		{
			y0 = rectPrice.nTop + (fMaxPrice - pKIndex->PAVG.M5[i])*MM;
      if(y0>rectPrice.nBottom-1){
        y0 = rectPrice.nBottom;
      }
			pLine5[np].x = x1;
			pLine5[np].y = y0;
		}
		
		//均价10
		if (pKIndex->PAVG.M10[i] !=0)
		{
			y0 = rectPrice.nTop + (fMaxPrice - pKIndex->PAVG.M10[i])*MM;
      if(y0>rectPrice.nBottom-1){
        y0 = rectPrice.nBottom;
      }
			pLine10[np].x = x1;
			pLine10[np].y = y0;
		}
		
		//均价20
		if (pKIndex->PAVG.M20[i] !=0)
		{
			y0 = rectPrice.nTop + (fMaxPrice - pKIndex->PAVG.M20[i])*MM;
      if(y0>rectPrice.nBottom-1){
        y0 = rectPrice.nBottom;
      }
			pLine20[np].x = x1;
			pLine20[np].y = y0;
		}
    
    //均价60
    if (pKIndex->PAVG.M60[i] !=0)
    {
      y0 = rectPrice.nTop + (fMaxPrice - pKIndex->PAVG.M60[i])*MM;
      if(y0>rectPrice.nBottom-1){
        y0 = rectPrice.nBottom;
      }
      pLine60[np].x = x1;
      pLine60[np].y = y0;
    }
		
		np++;
		
		
		x0 += nKLineWidth;
	}
	
	nUpLen = nULen;
	nDownLen = nDLen;
	
	x0 = LEFT_WIDTH(isLandscape) + SA_WIDTH + 1;
	np = 0;
  //量区域高　
	h = nVolHeight-2;
    
    //中间vol
    if (n_Mode == KLINE_MODE_SPECIAL) {
        int yVT,yVB;
        yVB = nMiddleVolTop + nMiddleVolHeight-1;
        float MV;
        MV = lMaxVolume*h;
        nULen = 0;
        nDLen = 0;
        x0 = LEFT_WIDTH(isLandscape) + 1;
        for(int i=nPosStart; i<nMaxCount; i++) {
            x0+=SA_WIDTH;
            x1 = x0 + w2;
            //量
            yVT = nMiddleVolTop + (MV - pKRes->kData[i].lVol*h)/lMaxVolume;
            
            r.nLeft = x0;
            r.nRight = x0+nKLineWidth;
            r.nTop = yVT;
            r.nBottom = yVB;
            r.nTop = (r.nTop == r.nBottom) ? r.nBottom - 1 : r.nTop;
            //add by jason 增加开盘涨跌停的特殊处理
            int nflag = [self isUpOrDown:i];//涨跌标志
            //end
            //蜡烛图，成交量
            if(nflag == 1) {
                pRectUpVol[nULen] = r;
                nULen++;
            }else {
                pRectDownVol[nDLen] = r;
                nDLen++;
            }
            np++;
            x0 += nKLineWidth;
        }
        //重置
        x0 = LEFT_WIDTH(isLandscape) + SA_WIDTH + 1;
        np = 0;
    }
    
	switch (nLineExType) {
		case KLINE_EX_TYPE_KDJ:
		{
			//kdj
			float MMKDJ;
			MMKDJ = h/(fMaxKDJ-fMinKDJ);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
				//KDJ		
				pLineK[np].x = pLineD[np].x = pLineJ[np].x = x1;
				pLineK[np].y = rectVol.nTop + (fMaxKDJ - KDJ_0_100(pKIndex->KDJ.K[i]))*MMKDJ;
				pLineD[np].y = rectVol.nTop + (fMaxKDJ - KDJ_0_100(pKIndex->KDJ.D[i]))*MMKDJ;
				pLineJ[np].y = rectVol.nTop + (fMaxKDJ - KDJ_0_100(pKIndex->KDJ.J[i]))*MMKDJ;
				np++;
				x0 += nKLineWidth+SA_WIDTH;
			}
		}
			break;
		case KLINE_EX_TYPE_RSI:
		{
			//rsi
			float MMRSI;
			MMRSI = h/(fMaxRSI-fMinRSI);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
				//rsi
				pLineRSI6[np].x = pLineRSI12[np].x = pLineRSI24[np].x = x1;
				pLineRSI6[np].y = rectVol.nTop + (fMaxRSI - pKIndex->RSI.RSI1[i])*MMRSI;
				pLineRSI12[np].y = rectVol.nTop + (fMaxRSI - pKIndex->RSI.RSI2[i])*MMRSI;
				pLineRSI24[np].y = rectVol.nTop + (fMaxRSI - pKIndex->RSI.RSI3[i])*MMRSI;
				np++;
				x0 += nKLineWidth+SA_WIDTH;
			}
		}
			break;
		case KLINE_EX_TYPE_MACD:
		{
			//macd
			float MMMACD;
			MMMACD = h/(fabs(fMaxMACD) + fabs(fMinMACD));
      if(fMaxMACD*fMinMACD>0) {
        MMMACD = h/fabs(fabs(fMaxMACD) -fabs(fMinMACD));
      }
			
      
      nMACD_Y_0 = rectVol.nTop + (fMaxMACD)*MMMACD;
      nMACD_Y_0 = nMACD_Y_0 > rectVol.nBottom - 2 ? rectVol.nBottom - 2 : nMACD_Y_0;
      nMACD_Y_0 = nMACD_Y_0 < rectVol.nTop + 2 ?  rectVol.nTop + 2 : nMACD_Y_0;
			
			int nDDUp,nDDDown;
			nDDUp = nDDDown = 0;
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
				//MACD
				pLineDIF[np].x = pLineDEA[np].x = x1;
				pLineDIF[np].y = rectVol.nTop + (fMaxMACD - pKIndex->MACD.DIF[i])*MMMACD;
				pLineDEA[np].y = rectVol.nTop + (fMaxMACD - pKIndex->MACD.DEA[i])*MMMACD;
				
				if(pKIndex->MACD.DIF[i]>pKIndex->MACD.DEA[i])
				{
					pLineDDUp[nDDUp].x = x1;
					pLineDDUp[nDDUp].y = rectVol.nTop + + (fMaxMACD-pKIndex->MACD.MACD[i])*MMMACD;
					nDDUp++;
				}
				else
				{
					pLineDDDown[nDDDown].x = x1;
					pLineDDDown[nDDDown].y = rectVol.nTop + (fMaxMACD-pKIndex->MACD.MACD[i])*MMMACD;
					nDDDown++;
				}
				np++;
				
				x0 += nKLineWidth+SA_WIDTH;
			}
			nMACD_DDUpLen = nDDUp;
			nMACD_DDDownLen = nDDDown;
		}
			break;
		case KLINE_EX_TYPE_WR:
		{
			//WR
			float MMWR;
			MMWR = h/(fMaxWR-fMinWR);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
				pLineWR1[np].x = pLineWR2[np].x = x1;
				pLineWR1[np].y = rectVol.nTop + (fMaxWR - pKIndex->WR.WR1[i])*MMWR;
				pLineWR2[np].y = rectVol.nTop + (fMaxWR - pKIndex->WR.WR2[i])*MMWR;
				np++;
				x0 += nKLineWidth+SA_WIDTH;
			}
		}
			break;
		case KLINE_EX_TYPE_BIAS:
		{
			//BIAS
			float MMBIAS;
			MMBIAS = h/(fMaxBIAS-fMinBIAS);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
				pLineBIAS1[np].x = pLineBIAS2[np].x = pLineBIAS3[np].x = x1;
				pLineBIAS1[np].y = rectVol.nTop + (fMaxBIAS - pKIndex->BIAS.BIAS1[i])*MMBIAS;
				pLineBIAS2[np].y = rectVol.nTop + (fMaxBIAS - pKIndex->BIAS.BIAS2[i])*MMBIAS;
				pLineBIAS3[np].y = rectVol.nTop + (fMaxBIAS - pKIndex->BIAS.BIAS3[i])*MMBIAS;
				np++;
				x0 += nKLineWidth+SA_WIDTH;
			}
		}
			break;
		case KLINE_EX_TYPE_ARBR:
		{
			//ARBR
			float MMARBR;
			MMARBR = h/(fMaxARBR-fMinARBR);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
				pLineAR[np].x = pLineBR[np].x = x1;
				pLineAR[np].y = rectVol.nTop + (fMaxARBR - pKIndex->ARBR.AR[i])*MMARBR;
				pLineBR[np].y = rectVol.nTop + (fMaxARBR - pKIndex->ARBR.BR[i])*MMARBR;
				np++;
				x0 += nKLineWidth+SA_WIDTH;
			}
		}
			break;
		case KLINE_EX_TYPE_CCI:
		{
			//CCI
			float MMCCI;
			MMCCI = h/(fMaxCCI-fMinCCI);
			float fSumCCI = fMaxCCI-fMinCCI;
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
				pLineCCI[np].x = x1;
				pLineCCI[np].y = rectVol.nTop + (fSumCCI - (pKIndex->CCI.CCI[i] - fMinCCI))*MMCCI;
				np++;
				x0 += nKLineWidth+SA_WIDTH;
			}
		}
			break;
		case KLINE_EX_TYPE_DMA:
		{
			//DMA
			float MMDMA;
			MMDMA = h/(fMaxDMA-fMinDMA);
			float fSumDMA = fMaxDMA-fMinDMA;
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
				pLineDDD[np].x = pLineAMA[np].x = x1;
				pLineDDD[np].y = rectVol.nTop + (fSumDMA - (pKIndex->DMA.DDD[i] - fMinDMA))*MMDMA;
				pLineAMA[np].y = rectVol.nTop + (fSumDMA - (pKIndex->DMA.AMA[i] - fMinDMA))*MMDMA;
				np++;
				x0 += nKLineWidth+SA_WIDTH;
			}
		}
			break;
		case KLINE_EX_TYPE_PSY:
		{
			//PSY
			float MMPSY;
			MMPSY = h/(fMaxPSY-fMinPSY);
			float fSumPSY = fMaxPSY-fMinPSY;
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
				pLinePSY[np].x = x1;
				pLinePSY[np].y = rectVol.nTop + (fSumPSY - (pKIndex->PSY.PSY[i] - fMinPSY))*MMPSY;
				np++;
				x0 += nKLineWidth+SA_WIDTH;
			}
		}
			break;
		case KLINE_EX_TYPE_BOLL:
		{
			//BOLL
			float MMBOLL;
			MMBOLL = h/(fMaxBOLL-fMinBOLL);
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
				pLineMID[np].x = pLineUPPER[np].x = pLineLOWER[np].x = x1;
				
				pLineMID[np].y = pKIndex->BOLL.MID[i] == 0 ? 0 : rectVol.nTop + (fMaxBOLL - pKIndex->BOLL.MID[i])*MMBOLL;
				pLineUPPER[np].y = pKIndex->BOLL.UPPER[i] == 0 ? 0 : rectVol.nTop + (fMaxBOLL - pKIndex->BOLL.UPPER[i])*MMBOLL;
				pLineLOWER[np].y = pKIndex->BOLL.LOWER[i] == 0 ? 0 :  rectVol.nTop + (fMaxBOLL - pKIndex->BOLL.LOWER[i])*MMBOLL;
				np++;
				x0 += nKLineWidth+SA_WIDTH;
			}
			
			//价
			x0 = LEFT_WIDTH(isLandscape) + 1;
			nULen = nDLen = 0;
			
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x0+=SA_WIDTH;
				x1 = x0 + w2;
				
				//最高最低
				y0 = rectVol.nTop + (fMaxBOLL - pKRes->kData[i].fHigh)*MMBOLL;
				y1 = rectVol.nTop + (fMaxBOLL - pKRes->kData[i].fLow)*MMBOLL;
				
			
				//add by jason
				int nflag = [self isUpOrDown:i];//涨跌标志
				//end
				
				//蜡烛图，成交量
				if(nflag == 1)
				//蜡烛图，成交量
				//if(pKRes->kData[i].fCur >= pKRes->kData[i].fOpen)
				{
					pBollUp[nULen].xCur = x0;
					pBollUp[nULen].yCur = rectVol.nTop + (fMaxBOLL - pKRes->kData[i].fCur)*MMBOLL; 
					pBollUp[nULen].xOpen = x0+nKLineWidth;
					pBollUp[nULen].yOpen = rectVol.nTop + (fMaxBOLL - pKRes->kData[i].fOpen)*MMBOLL; 
					
					pBollUp[nULen].x = x1;
					pBollUp[nULen].yHight = y0;
					pBollUp[nULen].yLow = y1;
					nULen++;
				}
				else
				{
					pBollDown[nDLen].xOpen = x0;
					pBollDown[nDLen].yOpen = rectVol.nTop + (fMaxBOLL - pKRes->kData[i].fOpen)*MMBOLL; 
					pBollDown[nDLen].xCur = x0+nKLineWidth;
					pBollDown[nDLen].yCur = rectVol.nTop + (fMaxBOLL - pKRes->kData[i].fCur)*MMBOLL; 
					
					pBollDown[nDLen].x = x1;
					pBollDown[nDLen].yHight = y0;
					pBollDown[nDLen].yLow = y1;
					nDLen++;
				}
				
				x0 += nKLineWidth;

			}
				
		}
			break;		
      //lisz add 20110916 start
    case KLINE_EX_TYPE_DDX:
    {
      //ddx
			float MMDDX;
			
			MMDDX = h/(fMaxDDX-fMinDDX);
			
			
			
			float MMDD;
			MMDD = absf(fMaxDDX)+absf(fMinDDX);
			
			
			nDDX_Y_0 = rectVol.nTop + (MMDD-absf(fMinDDX))/MMDD*h;
			
			int nDDUp,nDDDown;
			nDDUp = nDDDown = 0;
            int x2 = LEFT_WIDTH(isLandscape) + 1;
		    if (pKRes->nEffectiveCount == 0) {
				nMaxCount = 0;//add by jason 没有指标数据不进行计算
			}
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
        x2+=SA_WIDTH;
				//DDX
				pDDX1[np].x = pDDX2[np].x = pDDX3[np].x = x1;
				pDDX1[np].y = rectVol.nTop + (fMaxDDX - pKIndex->DDX.ddx1[i])*MMDDX;
				pDDX2[np].y = rectVol.nTop + (fMaxDDX - pKIndex->DDX.ddx2[i])*MMDDX;
        pDDX3[np].y = rectVol.nTop + (fMaxDDX - pKIndex->DDX.ddx3[i])*MMDDX;
				
				if(pKIndex->DDX.ddx[i]>0)
				{
					pLineDDXUp[nDDUp].nLeft = x2;
          pLineDDXUp[nDDUp].nRight = x2+nKLineWidth;
					pLineDDXUp[nDDUp].nTop = rectVol.nTop + (MMDD-(pKIndex->DDX.ddx[i]+absf(fMinDDX)))*MMDDX;
          pLineDDXUp[nDDUp].nBottom = nDDX_Y_0;
          if (pLineDDXUp[nDDUp].nTop == pLineDDXUp[nDDUp].nBottom) {
            pLineDDXUp[nDDUp].nTop--;
          }
					nDDUp++;
				}
				else
				{
					pLineDDXDown[nDDDown].nLeft = x2;
          pLineDDXDown[nDDDown].nRight = x2+nKLineWidth;
          pLineDDXDown[nDDDown].nTop = nDDX_Y_0;
					pLineDDXDown[nDDDown].nBottom = rectVol.nTop + (MMDD-(absf(fMinDDX)-absf(pKIndex->DDX.ddx[i])))*MMDDX;
          if (pLineDDXDown[nDDDown].nTop == pLineDDXDown[nDDDown].nBottom) {
            pLineDDXDown[nDDDown].nBottom++;
          }
					nDDDown++;
				}
        x2+=nKLineWidth;
        
        
				np++;
				
				x0 += nKLineWidth+SA_WIDTH;
			}
			nDDX_DDUpLen = nDDUp;
			nDDX_DDDownLen = nDDDown;
    }
      break;
    case KLINE_EX_TYPE_DDY:
    {
      //DDY，因DDX与DDY绘图完全一样，为了节省内存，目前DDY使用DDX的绘图结构。
			float MMDDX;
			MMDDX = h/(fMaxDDX-fMinDDX);
			
			
			float MMDD;
			MMDD = absf(fMaxDDX)+absf(fMinDDX);
			
			nDDX_Y_0 = rectVol.nTop + (MMDD-absf(fMinDDX))/MMDD*h;
			
			int nDDUp,nDDDown;
			nDDUp = nDDDown = 0;
      int x2 = LEFT_WIDTH(isLandscape) + 1;
		if (pKRes->nEffectiveCount == 0) {
			nMaxCount = 0;//add by jason 没有指标数据不进行计算
		}
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
        x2+=SA_WIDTH;
				//DDX
				pDDX1[np].x = pDDX2[np].x = pDDX3[np].x = x1;
				pDDX1[np].y = rectVol.nTop + (fMaxDDX - pKIndex->DDY.ddy1[i])*MMDDX;
				pDDX2[np].y = rectVol.nTop + (fMaxDDX - pKIndex->DDY.ddy2[i])*MMDDX;
        pDDX3[np].y = rectVol.nTop + (fMaxDDX - pKIndex->DDY.ddy3[i])*MMDDX;
				
				if(pKIndex->DDY.ddy[i]>0)
				{
					pLineDDXUp[nDDUp].nLeft = x2;
          pLineDDXUp[nDDUp].nRight = x2+nKLineWidth;
					pLineDDXUp[nDDUp].nTop = rectVol.nTop + (MMDD-(pKIndex->DDY.ddy[i]+absf(fMinDDX)))*MMDDX;
          pLineDDXUp[nDDUp].nBottom = nDDX_Y_0;
          if (pLineDDXUp[nDDUp].nTop == pLineDDXUp[nDDUp].nBottom) {
            pLineDDXUp[nDDUp].nTop--;
          }
					nDDUp++;
				}
				else
				{
					pLineDDXDown[nDDDown].nLeft = x2;
          pLineDDXDown[nDDDown].nRight = x2+nKLineWidth;
          pLineDDXDown[nDDDown].nTop = nDDX_Y_0;
					pLineDDXDown[nDDDown].nBottom = rectVol.nTop + (MMDD-(absf(fMinDDX)-absf(pKIndex->DDY.ddy[i])))*MMDDX;
          if (pLineDDXDown[nDDDown].nTop == pLineDDXDown[nDDDown].nBottom) {
            pLineDDXDown[nDDDown].nBottom++;
          }
					nDDDown++;
				}
        x2+=nKLineWidth;
        
        
				np++;
				
				x0 += nKLineWidth+SA_WIDTH;
			}
			nDDX_DDUpLen = nDDUp;
			nDDX_DDDownLen = nDDDown;
    }
      break;
    case KLINE_EX_TYPE_DDZ:
    {
      //DDY，因DDX与DDY绘图完全一样，为了节省内存，目前DDY使用DDX的绘图结构。
			float MMDDX;
      int MAX_WIDTH = 5;
			MMDDX = (h-MAX_WIDTH*2)/(fMaxDDX-fMinDDX);
			
			
			float MMDD;
			MMDD = absf(fMaxDDX)+absf(fMinDDX);
			
			nDDX_Y_0 = rectVol.nTop + (MMDD-absf(fMinDDX))/MMDD*h;
			
			int nDDUp,nDDDown;
			nDDUp = nDDDown = 0;
		if (pKRes->nEffectiveCount == 0) {
			nMaxCount = 0;//add by jason 没有指标数据不进行计算
		}
      //int x2 = LEFT_WIDTH(isLandscape) + 1;
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
        //x2+=SA_WIDTH;
				//DDX
				pDDX1[np].x = x1;
				pDDX1[np].y = rectVol.nTop + MAX_WIDTH + (fMaxDDX - pKIndex->DDZ.ddz[i])*MMDDX;
        
        pDDX2[np].x = x1;
        if (pKIndex->DDZ.ddz1[i]>=0) {
          pDDX2[np].y = pDDX1[np].y-min(pKIndex->DDZ.ddz1[i], MAX_WIDTH);
        }
        else{
           pDDX2[np].y = pDDX1[np].y-max(pKIndex->DDZ.ddz1[i], -MAX_WIDTH);
        }
        
//        if (pDDX2[np].y<rectVol.nTop) {
//          pDDX2[np].y=rectVol.nTop;
//        } else if (pDDX2[np].y>rectVol.nBottom) {
//          pDDX2[np].y=rectVol.nBottom;
//        }
        
				
				
        //x2+=nKLineWidth;
				np++;
				
				x0 += nKLineWidth+SA_WIDTH;
			}
			nDDX_DDUpLen = nDDUp;
			nDDX_DDDownLen = nDDDown;
    }
      break;
    case KLINE_EX_TYPE_BBD_RETAI:
    case KLINE_EX_TYPE_BBD_MAIN:
    {
      //DDY，因DDX与DDY绘图完全一样，为了节省内存，目前DDY使用DDX的绘图结构。
			float MMDDX;
			MMDDX = (h-6)/(fMaxDDX-fMinDDX);//线宽3，上下线宽3＊2
			
			float MMDD;
			MMDD = absf(fMaxDDX)+absf(fMinDDX);
			
			nDDX_Y_0 = rectVol.nTop + (MMDD-absf(fMinDDX))/MMDD*(h-6);
			
			int nDDUp,nDDDown;
			nDDUp = nDDDown = 0;
      
      double *pShareholdingRatio;
      double *pCurrentFluctuation;
      if (nLineExType==KLINE_EX_TYPE_BBD_RETAI) {
        pShareholdingRatio = pKIndex->BBDRetai.shareholdingRatio;
        pCurrentFluctuation = pKIndex->BBDRetai.currentFluctuation;
      } else {
        pShareholdingRatio = pKIndex->BBDMain.shareholdingRatio;
        pCurrentFluctuation = pKIndex->BBDMain.currentFluctuation;
      }
		if (pKRes->nEffectiveCount == 0) {
			nMaxCount = 0;//add by jason 没有指标数据不进行计算
		}
      //int x2 = LEFT_WIDTH(isLandscape) + 1;
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
        //x2+=SA_WIDTH;
				//DDX
				pDDX1[np].x = x1;
				pDDX1[np].y = rectVol.nTop + (fMaxDDX - pShareholdingRatio[i])*MMDDX + 3;
				
        
        if(pCurrentFluctuation[i]>0)
				{
					pLineDDXUp[nDDUp].nLeft = x1;
          pLineDDXUp[nDDUp].nRight = x1+2;
					pLineDDXUp[nDDUp].nTop = pDDX1[np].y - pCurrentFluctuation[i]*MMDDX;
          pLineDDXUp[nDDUp].nBottom = pDDX1[np].y;
          if (pLineDDXUp[nDDUp].nTop <= rectVol.nTop) {
            pLineDDXUp[nDDUp].nTop = rectVol.nTop-1;
          }
					nDDUp++;
				}
				else
				{
					pLineDDXDown[nDDDown].nLeft = x1;
          pLineDDXDown[nDDDown].nRight = x1+2;
          pLineDDXDown[nDDDown].nTop = pDDX1[np].y;
					pLineDDXDown[nDDDown].nBottom = pDDX1[np].y - pCurrentFluctuation[i]*MMDDX;
          if (pLineDDXDown[nDDDown].nBottom >= rectVol.nBottom) {
            pLineDDXDown[nDDDown].nBottom = rectVol.nBottom+1;
          }
					nDDDown++;
				}
       // x2+=nKLineWidth;
				
				np++;
				x0 += nKLineWidth+SA_WIDTH;
			}
		if (fMaxDDX != 0) {//add by jason 没有返回数据时fMaxDDX为0
			nDDX_DDUpLen = nDDUp;
			nDDX_DDDownLen = nDDDown;
		}
     
    }
      break;
    case KLINE_EX_TYPE_BBD:
    {
      //bbd
			double MMDDX;
			MMDDX = (h+0.0)/(fMaxBBD-fMinBBD);
			
			
			long64 MMDD;
			MMDD = absf(fMaxBBD)+absf(fMinBBD);
			
			nDDX_Y_0 = rectVol.nTop + (MMDD-absf(fMinBBD))/MMDD*h;
			
			int nDDUp,nDDDown;
			nDDUp = nDDDown = 0;
      int x2 = LEFT_WIDTH(isLandscape) + 1;
		if (pKRes->nEffectiveCount == 0) {
			nMaxCount = 0;//add by jason 没有指标数据不进行计算
		}
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x1 = x0 + w2;
        x2+=SA_WIDTH;
				//DDX
				pDDX1[np].x = pDDX2[np].x = pDDX3[np].x = x1;
				pDDX1[np].y = rectVol.nTop + (fMaxBBD - pKIndex->BBD.sum1[i])*MMDDX;
				pDDX2[np].y = rectVol.nTop + (fMaxBBD - pKIndex->BBD.sum2[i])*MMDDX;
        pDDX3[np].y = rectVol.nTop + (fMaxBBD - pKIndex->BBD.sum3[i])*MMDDX;
				
				if(pKIndex->BBD.bbd[i]>0)
				{
					pLineDDXUp[nDDUp].nLeft = x2;
          pLineDDXUp[nDDUp].nRight = x2+nKLineWidth;
					pLineDDXUp[nDDUp].nTop = rectVol.nTop + (MMDD-(pKIndex->BBD.bbd[i]+absf(fMinBBD)))*MMDDX;
          pLineDDXUp[nDDUp].nBottom = nDDX_Y_0;
          if (pLineDDXUp[nDDUp].nTop == pLineDDXUp[nDDUp].nBottom) {
            pLineDDXUp[nDDUp].nTop--;
          }
					nDDUp++;
				}
				else
				{
					pLineDDXDown[nDDDown].nLeft = x2;
          pLineDDXDown[nDDDown].nRight = x2+nKLineWidth;
          pLineDDXDown[nDDDown].nTop = nDDX_Y_0;
					pLineDDXDown[nDDDown].nBottom = rectVol.nTop + (MMDD-(absf(fMinBBD)-absf(pKIndex->BBD.bbd[i])))*MMDDX;
          if (pLineDDXDown[nDDDown].nTop == pLineDDXDown[nDDDown].nBottom) {
            pLineDDXDown[nDDDown].nBottom++;
          }
					nDDDown++;
				}
        x2+=nKLineWidth;
        
        
				np++;
				
				x0 += nKLineWidth+SA_WIDTH;
			}
			nDDX_DDUpLen = nDDUp;
			nDDX_DDDownLen = nDDDown;
    }
      break;
    case KLINE_EX_TYPE_AVG_VOL_SUM:
    {
      //vol
			int yVT,yVB;
			
			yVB = rectVol.nBottom-2;
			
			float MV;
			MV = fMaxDDX*h;
			int nDDUp;
			nDDUp = 0;
      x0 = LEFT_WIDTH(isLandscape) + 1;
		if (pKRes->nTrancEffectiveCount == 0) {
			nMaxCount = 0;//add by jason 没有指标数据不进行计算
		}
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x0+=SA_WIDTH;
				x1 = x0 + w2;
				//均额
				yVT = rectVol.nTop + (MV - pKIndex->AVG_VOL_SUM.avgSum[i]*h)/fMaxDDX;
				
				r.nLeft = x0+nKLineWidth/2-1;
				r.nRight = r.nLeft+2;
				r.nTop = yVT;
				r.nBottom = yVB;
				
        pLineDDXUp[nDDUp] = r;
        nDDUp++;
				
				np++;
				
				x0 += nKLineWidth;
			}
		if (fMaxDDX != 0) {//add by jason 没有返回数据时fMaxDDX为0
			 nDDX_DDUpLen = nDDUp;
		}else {
			nDDX_DDUpLen = 0;
		}

     
    }
      break;
      //lisz add 20110916 end
		case KLINE_EX_TYPE_VOL://量
		default:
		{
			//vol
			int yVT,yVB;
			
			yVB = rectVol.nBottom-1;//-2;
			
			float MV;
			MV = lMaxVolume*h;
			nULen = 0;
			nDLen = 0;
      x0 = LEFT_WIDTH(isLandscape) + 1;
			for(int i=nPosStart; i<nMaxCount; i++)
			{
				x0+=SA_WIDTH;
				x1 = x0 + w2;
				//量
				yVT = rectVol.nTop + (MV - pKRes->kData[i].lVol*h)/lMaxVolume;
				
				r.nLeft = x0;
				r.nRight = x0+nKLineWidth;
				r.nTop = yVT;
				r.nBottom = yVB;
				r.nTop = (r.nTop == r.nBottom) ? r.nBottom - 1 : r.nTop;
				
				//add by jason 增加开盘涨跌停的特殊处理        
        int nflag = [self isUpOrDown:i];//涨跌标志
        //end
				
				//蜡烛图，成交量
				if(nflag == 1)
				{
					pRectUpVol[nULen] = r;
					nULen++;
				}
				else
				{
					pRectDownVol[nDLen] = r;
					nDLen++;
				}
				
				np++;
				
				x0 += nKLineWidth;
			}
		}
			break;
	}
}

- (int)KLine_DrawMaxNumber
{
  float width = self.frame.size.width;
	return (self.frame.size.width-LEFT_WIDTH(isLandscape) - RIGHT_WIDTH(isLandscape) -2)/(nKLineWidth+SA_WIDTH);
}

- (void)addKLineWidth
{
	nKLineWidth+=2;
	if (nKLineWidth>21) {
		nKLineWidth=21;
	}
	bIsCalcStartPos = YES;
	[self calcData];
}

- (void)subKLineWidth
{
	nKLineWidth-=2;
	if (nKLineWidth<1) {
		nKLineWidth=1;
	}
	bIsCalcStartPos = YES;
	[self calcData];
}


-(void)calcRect
{
    if (n_Mode == KLINE_MODE_SPECIAL) {
        //出去中间的高度，三部分中上部分为2x，中下分别为x
        float fItemHeight = (self.frame.size.height- 4*TITLE_HEIGHT)/4;
		//价顶Y=价标题底
		nPriceTop = TITLE_HEIGHT;
		//价高H=每份高*2
		nPriceHeight = fItemHeight*2;
		//量顶Y=价顶Y+价高H+工具栏＋量标题高
        nMiddleVolTop = nPriceTop+nPriceHeight+TITLE_HEIGHT;
		//量高H=每份高*2
		nMiddleVolHeight = fItemHeight;
        nVolTop = 4*TITLE_HEIGHT + 3*fItemHeight; //这里的nVolTop代表下方的指标
        nVolHeight = fItemHeight;
	}else {
		//分成五份，每份=(总高-价标题－工具栏－成交量标题－时间标题)/5
        float fItemHeight = (self.frame.size.height-TITLE_HEIGHT-TITLE_HEIGHT-TITLE_HEIGHT)/5;
		//价顶Y=价标题底
        nPriceTop = TITLE_HEIGHT+1;
		//价高H=每份高*3
		nPriceHeight = fItemHeight*3;      //价格区域占3/5
        nVolTop = nPriceTop+nPriceHeight+0+TITLE_HEIGHT;
		//量高H=每份高*2
		nVolHeight = fItemHeight*2;        //量区域占2/5
	}
  
  mVerButton.frame = CGRectMake((self.frame.size.width-BUTTON_WIDTH)/2, nVolHeight + nVolTop + 2, BUTTON_WIDTH, TITLE_HEIGHT-4);
  mAveButton.frame = CGRectMake(2, 2, BUTTON_WIDTH, TITLE_HEIGHT-4);
  mComplexButton.frame = CGRectMake(self.frame.size.width-2-BUTTON_WIDTH, 2, BUTTON_WIDTH, TITLE_HEIGHT-4);
  if(isLandscape){
    mAveButton.frame = CGRectMake(LEFT_WIDTH(isLandscape)+2, 2, BUTTON_WIDTH, TITLE_HEIGHT-4);
    mComplexButton.frame = CGRectMake(self.frame.size.width-2-BUTTON_WIDTH-RIGHT_WIDTH(isLandscape), 2, BUTTON_WIDTH, TITLE_HEIGHT-4);
  }
  
  CGFloat fPadding = 10;
  CGFloat fArrowY = nPriceTop+nPriceHeight + (TITLE_HEIGHT - kArrowBtnW)/2;
    
    
    if (!isLandscape) {
        pLandScapeBtn.frame = CGRectMake((self.frame.size.width - kArrowBtnW - 10), fArrowY, kArrowBtnW, kArrowBtnW);
        mRightButton.frame = CGRectMake(pLandScapeBtn.frame.origin.x - fPadding - kArrowBtnW, fArrowY, kArrowBtnW, kArrowBtnW);
    }else {
        mRightButton.frame = CGRectMake((self.frame.size.width - kArrowBtnW - 10), fArrowY, kArrowBtnW, kArrowBtnW);
    }
    
  mUpButton.frame = CGRectMake(mRightButton.frame.origin.x - fPadding - kArrowBtnW, fArrowY, kArrowBtnW, kArrowBtnW);
  mDownButton.frame = CGRectMake(mUpButton.frame.origin.x - fPadding - kArrowBtnW, fArrowY, kArrowBtnW, kArrowBtnW);
  mLeftButton.frame = CGRectMake(mDownButton.frame.origin.x - fPadding - kArrowBtnW, fArrowY, kArrowBtnW, kArrowBtnW);
  mIndexButton.frame = CGRectMake(2, nVolTop-TITLE_HEIGHT , BUTTON_WIDTH, TITLE_HEIGHT-4);
  mVerButton.hidden = YES;
  mAveButton.hidden = YES;
  mComplexButton.hidden = NO;
  mIndexButton.hidden = YES;
  if (!isLandscape) {
    mVerButton.hidden = NO;
    mIndexButton.hidden = NO;
      mAveButton.hidden = NO;
  }
    
//    CGFloat fPointY = nPriceTop + nPriceHeight - TITLE_HEIGHT/2;
//    pLandScapeBtn.center = CGPointMake(CGRectGetWidth(self.frame) - 5 - 25, fPointY);
//    pLandScapeBtn.bounds = CGRectMake(0, 0, 40, TITLE_HEIGHT);
}


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    if (!pKRes) {
        return;
    }
	CGContextRef g = UIGraphicsGetCurrentContext();
  
    [self calcRect];
  
	int nHight;
	nHight = self.frame.size.height/3;
	GUI_RECT r;
  
	r.nLeft = LEFT_WIDTH(isLandscape);
	r.nRight = self.frame.size.width - RIGHT_WIDTH(isLandscape) -1;
  //价格框
    r.nTop = nPriceTop;
	r.nBottom = r.nTop+nPriceHeight;
	DrawTools_DrawRect(g, &r, frameColor, 0);
	//量、指标框
	r.nTop = nVolTop;
	r.nBottom = r.nTop + nVolHeight;
    DrawTools_DrawRect(g, &r, frameColor, 0);
    if (n_Mode == KLINE_MODE_SPECIAL) {
        r.nTop = nMiddleVolTop;
        r.nBottom = r.nTop + nMiddleVolHeight;
        DrawTools_DrawRect(g, &r, frameColor, 0);
    }
  
	//价格虚线
	int y;
	y = nPriceTop;
	int nh = nPriceHeight/(KVIEW_PRICE_SCALES_NUM-1);
	for (int i=1; i<KVIEW_PRICE_SCALES_NUM-1; i++) {
		y += nh;
        if (i == 2) {
            DrawTools_DrawLine(g, r.nLeft+1, y, r.nRight, y, scalesLineColor, PEN_STYLE_DOTLINE);
        }
	}
	//量刻度中线
	DrawTools_DrawLine(g, r.nLeft+1, nVolTop+nVolHeight/2, r.nRight, nVolTop+nVolHeight/2, scalesLineColor, PEN_STYLE_DOTLINE);
    if (n_Mode == KLINE_MODE_SPECIAL) {
        //指标刻度中线
        DrawTools_DrawLine(g, r.nLeft+1, nMiddleVolTop+nMiddleVolHeight/2, r.nRight, nMiddleVolTop+nMiddleVolHeight/2, scalesLineColor, PEN_STYLE_DOTLINE);
    }
//    绘制每月时间线
//    [self drawBackgroudTimeLine:pKRes->kLineType context:g];
    
	
    //绘制K线图
	for(int i=0; i<nUpLen; i++) {
		DrawTools_DrawLine(g, pUp[i].x, pUp[i].yHight, pUp[i].x, pUp[i].yLow, nUpFrameColor, 0);
	}
	
	for(int i=0; i<nDownLen; i++) {
		DrawTools_DrawLine(g, pDown[i].x, pDown[i].yHight, pDown[i].x, pDown[i].yLow, nDownFullColor, 0);
	}
	DrawTools_FullRectArr(g, pRectUp, nUpLen, nUpFrameColor);
	DrawTools_FullRectArr(g, pRectDown, nDownLen, nDownFullColor);
	
	int nLineCount = [self KLine_DrawMaxNumber];//pKData->nCount - nPosStart;
	if (nLineCount>pKRes->nTotalCount) {
		nLineCount=pKRes->nTotalCount;
	}
	
	GUI_RECT rText;
	char sTemp[64];
	char *sFormat;
	char sFormat2[]="%.2f";
	char sFormat3[]="%.3f";
	rText.nRight = rText.nLeft + 80;
	if (pKRes->codeinfo.decNum==0x03) {
		sFormat = sFormat3;
	}else {
		sFormat = sFormat2;
	}
	//
	int nPosT;
	
		/* m5 m10 m20*/
    DrawTools_DrawPath(g, pLine60, nLineCount, nM60Color);
    DrawTools_DrawPath(g, pLine20, nLineCount, nM20Color);
    DrawTools_DrawPath(g, pLine10, nLineCount, nM10Color);
    DrawTools_DrawPath(g, pLine5, nLineCount, nM5Color);
		
    //绘价标题
    rText.nLeft = LEFT_WIDTH(isLandscape);
    rText.nRight = rText.nLeft+self.frame.size.width-LEFT_WIDTH(isLandscape) - RIGHT_WIDTH(isLandscape);
    rText.nTop = nPriceTop;
    rText.nBottom = rText.nTop+TITLE_HEIGHT;
    
    
    nPosT = nPosStart + nPos;
    if (nPosT<0 || nPos<0) {
        nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
    }
        
    //绘透明背景
    rText.nLeft = LEFT_WIDTH(isLandscape) + 5;
    rText.nRight = rText.nLeft + 240;
    rText.nTop = nPriceTop + 4;
    rText.nBottom = rText.nTop + 9;
//    DrawTools_FullARect(g, &rText, 0xf5f5f5, 0.5);
    
    CGFloat fFontSize = 9;
    CGFloat fMaxW = 100;
    UIFont *pFont = [UIFont systemFontOfSize:fFontSize];

    sprintf(sTemp, sFormat, pKIndex->PAVG.M5[nPosT]);
    NSString *pStr = [NSString stringWithFormat:@"MA%d:%s",pKIndex->PAVG_N1,sTemp];
    CGFloat fBlockW = [pStr boundingRectWithSize:CGSizeMake(fMaxW, TITLE_HEIGHT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: pFont} context:nil].size.width;
    
    rText.nLeft = CGRectGetMaxX(mAveButton.frame) + 5;
    if (isLandscape) {
        rText.nLeft = LEFT_WIDTH(isLandscape) + 10;
    }
    rText.nRight = rText.nLeft + fBlockW;
    rText.nTop = 1;
    rText.nBottom = rText.nTop+TITLE_HEIGHT;
      DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), nM5Color, AGIN_LEFT, fFontSize);
    
      sprintf(sTemp, sFormat, pKIndex->PAVG.M10[nPosT]);
      pStr = [NSString stringWithFormat:@"%d:%s",pKIndex->PAVG_N2,sTemp];
      fBlockW = [pStr boundingRectWithSize:CGSizeMake(fMaxW, TITLE_HEIGHT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: pFont} context:nil].size.width;
		rText.nLeft = rText.nRight + 5;
		rText.nRight=rText.nLeft + fBlockW;
      DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), nM10Color, AGIN_LEFT, fFontSize);
		
      sprintf(sTemp, sFormat, pKIndex->PAVG.M20[nPosT]);
      pStr = [NSString stringWithFormat:@"%d:%s",pKIndex->PAVG_N3,sTemp];
      fBlockW = [pStr boundingRectWithSize:CGSizeMake(fMaxW, TITLE_HEIGHT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: pFont} context:nil].size.width;
		rText.nLeft = rText.nRight + 5;
		rText.nRight=rText.nLeft + fBlockW;
    rText.nBottom = rText.nBottom;
      DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), nM20Color, AGIN_LEFT, fFontSize);

    
      sprintf(sTemp, sFormat, pKIndex->PAVG.M60[nPosT]);
      pStr = [NSString stringWithFormat:@"%d:%s",pKIndex->PAVG_N4,sTemp];
      fBlockW = [pStr boundingRectWithSize:CGSizeMake(fMaxW, TITLE_HEIGHT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: pFont} context:nil].size.width;
    rText.nLeft = rText.nRight + 5;
    rText.nRight=rText.nLeft+fBlockW;
    rText.nBottom = rText.nBottom;
      DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), nM60Color, AGIN_LEFT, fFontSize);
		
	
	//时间
    int timeTop = nVolTop;
    if (n_Mode == KLINE_MODE_SPECIAL) {
        timeTop = nMiddleVolTop;
    }
	rText.nLeft = LEFT_WIDTH(isLandscape);
	rText.nRight = self.frame.size.width - RIGHT_WIDTH(isLandscape);
	rText.nTop = timeTop + nVolHeight;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	
	char sShowDate[64];
	memset(sShowDate, 0, sizeof(sShowDate));
	[self formatShowDate:pKRes->kData[nPosStart].nDate withDis:sShowDate];
	
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithUTF8String:sShowDate]), /*0x00AAFF*/nVolTitleColor, AGIN_LEFT);
	nPosT = nPosStart + [self KLine_DrawMaxNumber];
	if (nPosT>=pKRes->nTotalCount+pKRes->nKStartPos) {
		nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
	}
	memset(sShowDate, 0, sizeof(sShowDate));
	[self formatShowDate:pKRes->kData[nPosT].nDate withDis:sShowDate];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithUTF8String:sShowDate]), /*0x00AAFF*/nVolTitleColor, AGIN_RIGHT);
    
    //绘价刻度值
    rText.nLeft = GAP_X;
    if(isLandscape){
      rText.nLeft = 0;
    }
    rText.nRight = rText.nLeft+LEFT_GAP_WIDTH;
    rText.nTop = nPriceTop;
    rText.nBottom = rText.nTop+TITLE_HEIGHT;
    
    sprintf(sTemp, sFormat, fScalesPrice[0]);
    if(!isLandscape){
      DrawTools_DrawText(g, &rText, sTemp, /*0xFF0000*/nVolTitleColor, AGIN_LEFT);
    }else{
      rText.nLeft = 0;
      DrawTools_DrawText(g, &rText, sTemp, /*0xFF0000*/nVolTitleColor, AGIN_RIGHT);
    }

    y = nPriceTop;
    for (int i=1; i<KVIEW_PRICE_SCALES_NUM-1; i++) {
        y += nh;
        rText.nTop = y-TITLE_HEIGHT/2;
        rText.nBottom = y+TITLE_HEIGHT/2;
        sprintf(sTemp, sFormat, fScalesPrice[i]);
      if (i == 2) {
        if(!isLandscape){
          DrawTools_DrawText(g, &rText, sTemp, /*0xFF0000*/nVolTitleColor, AGIN_LEFT);
        }else{
          DrawTools_DrawText(g, &rText, sTemp, /*0xFF0000*/nVolTitleColor, AGIN_RIGHT);
        }
      }
		}
		rText.nTop = nPriceTop+nPriceHeight - TITLE_HEIGHT;
		rText.nBottom = rText.nTop+TITLE_HEIGHT;
		sprintf(sTemp, sFormat, fScalesPrice[KVIEW_PRICE_SCALES_NUM-1]);
    if(!isLandscape){
    		DrawTools_DrawText(g, &rText, sTemp,/*0xFF0000*/nVolTitleColor, AGIN_LEFT);
    }else{
    		DrawTools_DrawText(g, &rText, sTemp,/*0xFF0000*/nVolTitleColor, AGIN_RIGHT);
    }
	
    if (n_Mode == KLINE_MODE_SPECIAL) {
        //绘制vol
        [self drawVol:g];
    }
	/*根据类型绘指标*/
	switch (nLineExType) {
		case KLINE_EX_TYPE_MACD:
			[self drawMACD:g withCount:nLineCount];
			break;
		case KLINE_EX_TYPE_RSI:
			[self drawRSI:g withCount:nLineCount];
			break;
		case KLINE_EX_TYPE_KDJ:
			[self drawKDJ:g withCount:nLineCount];
			break;
		case KLINE_EX_TYPE_WR:
			[self drawWR:g withCount:nLineCount];
			break;
		case KLINE_EX_TYPE_BIAS:
			[self drawBIAS:g withCount:nLineCount];
			break;
		case KLINE_EX_TYPE_ARBR:
			[self drawARBR:g withCount:nLineCount];
			break;
		case KLINE_EX_TYPE_CCI:
			[self drawCCI:g withCount:nLineCount];
			break;
		case KLINE_EX_TYPE_DMA:
			[self drawDMA:g withCount:nLineCount];
			break;
		case KLINE_EX_TYPE_PSY:
			[self drawPSY:g withCount:nLineCount];
			break;
		case KLINE_EX_TYPE_BOLL:
			[self drawBOLL:g withCount:nLineCount];
			break;
      //lisz add 20110916 start
    case KLINE_EX_TYPE_DDX:
    case KLINE_EX_TYPE_DDY:
    case KLINE_EX_TYPE_DDZ:
      [self drawDDX:g withCount:nLineCount];
			break;
    case KLINE_EX_TYPE_BBD_RETAI:
    case KLINE_EX_TYPE_BBD_MAIN:
      [self drawBBDRetaiMain:g withCount:nLineCount];
      break;
    case KLINE_EX_TYPE_BBD:
      [self drawBBD:g withCount:nLineCount];
      break;
    case KLINE_EX_TYPE_AVG_VOL_SUM:
      [self drawAvgVolSum:g withCount:nLineCount];
      break;
      //lisz add 20110916 end
		case KLINE_EX_TYPE_VOL:
		default:
			[self drawVol:g];
			break;
	}
	
    [self draw10LineWithContext:g];

}

- (void)drawBackgroudTimeLine:(int)lineType context:(CGContextRef)g
{
    if (pTimeLineArrayM.count <= 0) {
        return;
    }
    
    switch (lineType) {
        case QUOTELV_K_DATE:
        case QUOTELV_K_MONTH:
        {
            for (int i = 0;i < pTimeLineArrayM.count;i++) {
                if (i > 0) {
                    NSArray *timeLine = pTimeLineArrayM[i];
                    int nStartIndex = [timeLine[0] intValue];
                    int nChinaDate = [timeLine[1] intValue];
                    int x;
                    x = [pKLineMiddlePointArray[nStartIndex - nPosStart] intValue];
                    DrawTools_DrawLine(g, x, nPriceTop, x, nPriceTop+nPriceHeight, 0xdddddd, 0);
                    //            [self drawNewLine:g startPoint:CGPointMake(x, nPriceTop) endPoint:CGPointMake(x, nPriceTop+nPriceHeight) color:0xdddddd lineWidth:0.5];
                    
                    GUI_RECT rText;
                    rText.nLeft = x - 20;
                    rText.nRight = x + 20;
                    rText.nTop = nPriceTop + nPriceHeight;
                    rText.nBottom = rText.nTop+TITLE_HEIGHT;
                    
                    DrawTools_DrawFAText(g, &rText, [[NSString stringWithFormat:@"%d",nChinaDate] UTF8String], nVolTitleColor, AGIN_CENTER, 8, 1);
                }
                
            }
        }
            break;
        case QUOTELV_K_WEEK:
        {
            for (int i = 1;i < pTimeLineArrayM.count;i++) {
                NSArray *timeLine = pTimeLineArrayM[i];
                int nStartIndex = [timeLine[0] intValue];
                int nChinaDate = [timeLine[1] intValue];
                int x;
                x = [pKLineMiddlePointArray[nStartIndex - nPosStart] intValue];
                DrawTools_DrawLine(g, x, nPriceTop, x, nPriceTop+nPriceHeight, 0xdddddd, 0);
                //            [self drawNewLine:g startPoint:CGPointMake(x, nPriceTop) endPoint:CGPointMake(x, nPriceTop+nPriceHeight) color:0xdddddd lineWidth:0.5];
                
                GUI_RECT rText;
                rText.nLeft = x - 20;
                rText.nRight = x + 20;
                rText.nTop = nPriceTop + nPriceHeight;
                rText.nBottom = rText.nTop+TITLE_HEIGHT;
                
                DrawTools_DrawFAText(g, &rText, [[NSString stringWithFormat:@"%d",nChinaDate] UTF8String], nVolTitleColor, AGIN_CENTER, 8, 1);
                
            }
        }
            break;
            
        default:
            break;
    }
}

- (void)draw10LineWithContext:(CGContextRef)g
{
    if (!isShow10Line) {
        mLeftView.hidden = YES;
        mBottomView.hidden = YES;
        return;
    }
    if (nPos>=0) {//绘十字线
        int x;
        x = LEFT_WIDTH(isLandscape) + 1 + SA_WIDTH + (nPos*(nKLineWidth+SA_WIDTH))+ nKLineWidth/2;
        DrawTools_DrawLine(g, x, nPriceTop, x, nPriceTop+nPriceHeight, nTenLineColor, 0);
        DrawTools_DrawLine(g, x, nVolTop, x, nVolTop+nVolHeight, nTenLineColor, 0);
        if (n_Mode == KLINE_MODE_SPECIAL) {
            DrawTools_DrawLine(g, x, nMiddleVolTop, x, nMiddleVolTop+nMiddleVolHeight, nTenLineColor, 0);
        }
        //水平线
        if (ty > TITLE_HEIGHT && ty < nVolTop - TITLE_HEIGHT) {
            DrawTools_DrawLine(g, LEFT_GAP_WIDTH, ty, self.frame.size.width-RIGHT_WIDTH(isLandscape), ty, nTenLineColor, 0);
            mLeftView.hidden = NO;
        }else {
            mLeftView.hidden = YES;
        }
        
        float y;
        y = ty - mLeftView.frame.size.height / 2;
        mLeftView.frame = CGRectMake(0 , y, mLeftView.frame.size.width, mLeftView.frame.size.height);
        
        NSInteger nIndex = nPosStart+nPos;
        QUOTELV_K_POINT *kPoint = &pKRes->kData[nIndex];
        float fCurPrice = kPoint->fCur;
        if (pKRes->codeinfo.decNum==0x03) {
            [mLeft setText:[NSString stringWithFormat:@"%.3f",fCurPrice]];
        }else {
            [mLeft setText:[NSString stringWithFormat:@"%.2f",fCurPrice]];
        }
        x = x - mBottomView.frame.size.width / 2;
        y = nPriceTop + nPriceHeight + 1;
        mBottomView.frame = CGRectMake(x,y,mBottomView.frame.size.width,mBottomView.frame.size.height);
        char buf[32];
        memset(buf,0,32);
        [self formatShowDate:pKRes->kData[nPosStart + nPos].nDate withDis:buf];
        [mBottom setText:[NSString stringWithUTF8String:buf]];
        mBottomView.hidden = NO;
      
    }else {
        mLeftView.hidden = YES;
        mBottomView.hidden = YES;
    }
}

-(void)drawVol:(CGContextRef)g
{
	DrawTools_FullRectArr(g, pRectUpVol, nUpLen, nUpFrameColor);
	DrawTools_FullRectArr(g, pRectDownVol, nDownLen, /*0x00FFFF*/nDownFullColor);
	
	GUI_RECT rText;
	
    int volTop = nVolTop;
    if (n_Mode == KLINE_MODE_SPECIAL) {
        volTop = nMiddleVolTop;
    }
    
	//量刻度
  rText.nLeft = GAP_X;
  rText.nTop = volTop;
  if(isLandscape){
    rText.nLeft = 0;
    rText.nTop = volTop-TITLE_HEIGHT/2;
  }
  rText.nRight = rText.nLeft+LEFT_GAP_WIDTH;;
	rText.nBottom = volTop+TITLE_HEIGHT;
  DrawTools_DrawNSFText(g, &rText, (__bridge void *)(VolSumShow(lScalesVolume[0])), nVolTitleColor, AGIN(!isLandscape), 9);
  
  rText.nTop = volTop+nVolHeight/2;//-TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSFText(g, &rText, (__bridge void *)(VolSumShow(lScalesVolume[1])), nVolTitleColor, AGIN(!isLandscape), 9);
	
	int nPosT;
	nPosT = nPosStart + nPos;
	if (nPosT<0 || nPos<0) {
		nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
	}
	
	//绘量标题
	rText.nLeft = LEFT_WIDTH(isLandscape);
	rText.nRight = self.frame.size.width;
	rText.nTop = volTop-TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	
  //VOL
    if (isLandscape) {
        rText.nLeft = LEFT_GAP_WIDTH+15;
        rText.nRight = LEFT_GAP_WIDTH;
        DrawTools_DrawNSText(g, &rText, @"VOL", nIndexsColor, AGIN_RIGHT);
    }else {
        DrawTools_DrawNSText(g, &rText, @"成交量", nIndexsColor, AGIN_LEFT);
    }
	
}

-(void)drawKDJ:(CGContextRef)g withCount:(int)nCount
{
	DrawTools_DrawPath(g, pLineK, nCount, /*0xFFFFFF*/nM5Color);
	DrawTools_DrawPath(g, pLineD, nCount, /*0xFFFF00*/nM10Color);
	DrawTools_DrawPath(g, pLineJ, nCount, /*0xEA00FF*/nM20Color);
	
	GUI_RECT rText;
	
	//刻度
  rText.nLeft = GAP_X;
  rText.nTop = nVolTop;
  if(isLandscape){
    rText.nLeft = 0;
    rText.nTop = nVolTop-TITLE_HEIGHT/2;
  }
	rText.nRight = rText.nLeft+LEFT_GAP_WIDTH;;
	rText.nBottom = nVolTop+TITLE_HEIGHT;
  
	DrawTools_DrawNSText(g, &rText, @"100", /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop + nVolHeight/2 - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop + TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, @"50", /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop + nVolHeight - TITLE_HEIGHT;
	rText.nBottom = rText.nTop + TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, @"0", /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	int nPosT;
	nPosT = nPosStart + nPos;
	if (nPosT<0 || nPos < 0) {
		nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
	}
  
  //透明背景
  NSString *pStr;
  pStr = [NSString stringWithFormat:@"K:%.3f", pKIndex->KDJ.K[nPosT]];
  CGSize charSizeOne = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
  pStr = [NSString stringWithFormat:@"D:%.3f", pKIndex->KDJ.D[nPosT]];
  CGSize charSizeTwo = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
  pStr = [NSString stringWithFormat:@"J:%.3f", pKIndex->KDJ.J[nPosT]];
  CGSize charSizeThree = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
  rText.nLeft = LEFT_WIDTH(isLandscape) + 5;
  rText.nRight = rText.nLeft + charSizeOne.width + 10 + charSizeTwo.width + 10 + charSizeThree.width;
  rText.nTop = nVolTop + 4;
  rText.nBottom = rText.nTop + 9;
//    DrawTools_FullARect(g, &rText, 0xf5f5f5, 0.5);
	
	//绘量标题
	rText.nLeft = 2*LEFT_GAP_WIDTH + 15;
	rText.nRight = self.frame.size.width;
	rText.nTop = nVolTop-TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
//	NSString *pStr;
	pStr = [NSString stringWithFormat:@"K:%.3f", pKIndex->KDJ.K[nPosT]];
	CGSize charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFFFF*/nM5Color, AGIN(!isLandscape));
	rText.nLeft = rText.nLeft+charSize.width+10;
	pStr = [NSString stringWithFormat:@"D:%.3f", pKIndex->KDJ.D[nPosT]];
	charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFF00*/nM10Color, AGIN(!isLandscape));
	rText.nLeft = rText.nLeft+charSize.width+10;
	pStr = [NSString stringWithFormat:@"J:%.3f", pKIndex->KDJ.J[nPosT]];
	charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xEA00FF*/nM20Color, AGIN(!isLandscape));
    
  //KDJ
  rText.nLeft = LEFT_GAP_WIDTH+15;
  rText.nRight = LEFT_GAP_WIDTH;
  rText.nTop = nVolTop - TITLE_HEIGHT;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, @"KDJ", nIndexsColor, AGIN_RIGHT);
}

-(void)drawRSI:(CGContextRef)g withCount:(int)nCount
{
	if (pKIndex->RSI.RSI1[0] == 0) {
		DrawTools_DrawPath(g, pLineRSI6+1, nCount-1, /*0xFFFFFF*/nM5Color);
		DrawTools_DrawPath(g, pLineRSI12+1, nCount-1, /*0xFFFF00*/nM10Color);
		DrawTools_DrawPath(g, pLineRSI24+1, nCount-1, /*0xFF00FF*/nM20Color);
	}else {
		DrawTools_DrawPath(g, pLineRSI6, nCount, /*0xFFFFFF*/nM5Color);
		DrawTools_DrawPath(g, pLineRSI12, nCount, /*0xFFFF00*/nM10Color);
		DrawTools_DrawPath(g, pLineRSI24, nCount, /*0xFF00FF*/nM20Color);
	}
	
	GUI_RECT rText;
	
  //刻度
  rText.nLeft = GAP_X;
  rText.nTop = nVolTop;
  if(isLandscape){
    rText.nLeft = 0;
    rText.nTop = nVolTop-TITLE_HEIGHT/2;
  }
  rText.nRight = rText.nLeft+LEFT_GAP_WIDTH;;
  rText.nBottom = nVolTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesRSI[0]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop + nVolHeight/2 - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop + TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesRSI[1]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop + nVolHeight - TITLE_HEIGHT;
	rText.nBottom = rText.nTop + TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesRSI[2]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	int nPosT;
	nPosT = nPosStart + nPos;
	if (nPosT<0 || nPos < 0) {
		nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
	}
    
    //透明背景
    NSString *pStr;
    pStr = [NSString stringWithFormat:@"RSI6:%.3f", pKIndex->RSI.RSI1[nPosT]];
    CGSize charSizeOne = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
    pStr = [NSString stringWithFormat:@"RSI12:%.3f", pKIndex->RSI.RSI2[nPosT]];
    CGSize charSizeTwo = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
    pStr = [NSString stringWithFormat:@"RSI24:%.3f", pKIndex->RSI.RSI3[nPosT]];
    CGSize charSizeThree = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
    rText.nLeft = LEFT_WIDTH(isLandscape) + 5;
    rText.nRight = rText.nLeft + charSizeOne.width + 10 + charSizeTwo.width + 10 + charSizeThree.width;
    rText.nTop = nVolTop + 4;
    rText.nBottom = rText.nTop + 9;
//    DrawTools_FullARect(g, &rText, 0xf5f5f5, 0.5);
	
	//绘量标题
  rText.nLeft = 2*LEFT_GAP_WIDTH + 15;
  rText.nRight = self.frame.size.width;
	rText.nTop = nVolTop-TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
//	NSString *pStr;
	pStr = [NSString stringWithFormat:@"RSI6:%.3f", pKIndex->RSI.RSI1[nPosT]];
	CGSize charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFFFF*/nM5Color, AGIN_LEFT);
	//因为显示不下，暂时不显示
	rText.nLeft = rText.nLeft+charSize.width+10;
	pStr = [NSString stringWithFormat:@"RSI12:%.3f", pKIndex->RSI.RSI2[nPosT]];
	charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFF00*/nM10Color, AGIN_LEFT);
	rText.nLeft = rText.nLeft+charSize.width+10;
	pStr = [NSString stringWithFormat:@"RSI24:%.3f", pKIndex->RSI.RSI3[nPosT]];
	charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFF00FF*/nM20Color, AGIN_LEFT);
    
  //RSI
  rText.nLeft = LEFT_GAP_WIDTH+15;
  rText.nRight = LEFT_GAP_WIDTH;
  rText.nTop = nVolTop - TITLE_HEIGHT;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, @"RSI", nIndexsColor, AGIN_RIGHT);
}


-(void)drawMACD:(CGContextRef)g withCount:(int)nCount
{
	DrawTools_DrawLine(g, LEFT_WIDTH(isLandscape), nMACD_Y_0, self.frame.size.width - RIGHT_WIDTH(isLandscape), nMACD_Y_0, frameColor, PEN_STYLE_DOTLINE);
	for(int i=0; i<nMACD_DDUpLen; i++)
	{
		DrawTools_DrawLine(g, pLineDDUp[i].x, pLineDDUp[i].y, pLineDDUp[i].x, nMACD_Y_0, nUpFrameColor, 0);
	}
	for(int i=0; i<nMACD_DDDownLen; i++)
	{
		DrawTools_DrawLine(g, pLineDDDown[i].x, pLineDDDown[i].y, pLineDDDown[i].x, nMACD_Y_0, /*0x00FF00*/nDownFullColor, 0);
	}
	DrawTools_DrawPath(g, pLineDIF, nCount, /*0xFFFFFF*/nM5Color);
	DrawTools_DrawPath(g, pLineDEA, nCount, /*0xFFFF00*/nM10Color);
	
	GUI_RECT rText;
	
  rText.nLeft = GAP_X;
  rText.nTop = nVolTop;
  if(isLandscape){
    rText.nLeft = 0;
    rText.nTop = nVolTop-TITLE_HEIGHT/2;
  }
  rText.nRight = rText.nLeft+LEFT_GAP_WIDTH;;
  rText.nBottom = nVolTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesMACD[0]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop + nVolHeight/2 - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop + TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesMACD[1]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop + nVolHeight - TITLE_HEIGHT;;
	rText.nBottom = rText.nTop + TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesMACD[2]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	int nPosT;
	nPosT = nPosStart + nPos;
	if (nPosT<0 || nPos < 0) {
		nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
	}
    
  //透明背景
  NSString *pStr;
  pStr = [NSString stringWithFormat:@"DIF:%.3f", pKIndex->MACD.DIF[nPosT]];
  CGSize charSizeOne = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
  pStr = [NSString stringWithFormat:@"DEA:%.3f", pKIndex->MACD.DEA[nPosT]];
  CGSize charSizeTwo = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
  pStr = [NSString stringWithFormat:@"MACD:%.3f", pKIndex->MACD.DIF[nPosT]-pKIndex->MACD.DEA[nPosT]];
  CGSize charSizeThree = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
  rText.nLeft = LEFT_WIDTH(isLandscape) + 5;
  rText.nRight = rText.nLeft + charSizeOne.width + 5 + charSizeTwo.width + 5 + charSizeThree.width;
  rText.nTop = nVolTop + 4;
  rText.nBottom = rText.nTop + 9;
//    DrawTools_FullARect(g, &rText, 0xf5f5f5, 0.5);
	
	//绘量标题
  rText.nLeft = 2*LEFT_GAP_WIDTH + 15;
  rText.nRight = self.frame.size.width;
	rText.nTop = nVolTop-TITLE_HEIGHT;
	rText.nBottom = rText.nTop + TITLE_HEIGHT;
//	NSString *pStr;
	pStr = [NSString stringWithFormat:@"DIF:%.3f", pKIndex->MACD.DIF[nPosT]];
	CGSize charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFFFF*/nM5Color, AGIN_LEFT);
	rText.nLeft = rText.nLeft+charSize.width+5;
	pStr = [NSString stringWithFormat:@"DEA:%.3f", pKIndex->MACD.DEA[nPosT]];
	charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFF00*/nM10Color, AGIN_LEFT);
	rText.nLeft = rText.nLeft+charSize.width+5;
	pStr = [NSString stringWithFormat:@"MACD:%.3f", pKIndex->MACD.DIF[nPosT]-pKIndex->MACD.DEA[nPosT]];
	charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFF00FF*/nM20Color, AGIN_LEFT);
    
    //MACD
  rText.nLeft = LEFT_GAP_WIDTH+15;
  rText.nRight = LEFT_GAP_WIDTH;
  rText.nTop = nVolTop - TITLE_HEIGHT;
  rText.nBottom = rText.nTop + TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, @"MACD", nIndexsColor, AGIN_RIGHT);
}

-(void)drawWR:(CGContextRef)g withCount:(int)nCount
{
	DrawTools_DrawPath(g, pLineWR1, nCount, /*0xFFFFFF*/nM5Color);
	DrawTools_DrawPath(g, pLineWR2, nCount, /*0xFFFF00*/nM10Color);
	
	GUI_RECT rText;
	
  rText.nLeft = GAP_X;
  rText.nTop = nVolTop;
  if(isLandscape){
    rText.nLeft = 0;
    rText.nTop = nVolTop-TITLE_HEIGHT/2;
  }
  rText.nRight = rText.nLeft+LEFT_GAP_WIDTH;;
  rText.nBottom = nVolTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesWR[0]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop + nVolHeight/2 - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesWR[1]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop + nVolHeight - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesWR[2]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	
	int nPosT;
	nPosT = nPosStart + nPos;
	if (nPosT<0 || nPos < 0) {
		nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
	}
	
	//绘量标题
  rText.nLeft = 2*LEFT_GAP_WIDTH + 15;
  rText.nRight = self.frame.size.width;
	rText.nTop = nVolTop-TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	NSString *pStr;
	pStr = [NSString stringWithFormat:@"WR1:%.3f", pKIndex->WR.WR1[nPosT]];
	CGSize charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFFFF*/nM5Color, AGIN_LEFT);
	rText.nLeft = rText.nLeft+charSize.width+10;
	pStr = [NSString stringWithFormat:@"WR2:%.3f", pKIndex->WR.WR2[nPosT]];
	charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFF00*/nM10Color, AGIN_LEFT);
  
  //WR
  rText.nLeft = LEFT_GAP_WIDTH+15;
  rText.nRight = LEFT_GAP_WIDTH;
  rText.nTop = nVolTop - TITLE_HEIGHT;
  rText.nBottom = rText.nTop + TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, @"WR", nIndexsColor, AGIN_RIGHT);
}

-(void)drawBIAS:(CGContextRef)g withCount:(int)nCount
{
	DrawTools_DrawPath(g, pLineBIAS1, nCount, /*0xFFFFFF*/nM5Color);
	DrawTools_DrawPath(g, pLineBIAS2, nCount,  /*0xFFFF00*/nM10Color);
	DrawTools_DrawPath(g, pLineBIAS3, nCount,  /*0xFF00FF*/nM20Color);
	
	GUI_RECT rText;
	
  rText.nLeft = GAP_X;
  rText.nTop = nVolTop;
  if(isLandscape){
    rText.nLeft = 0;
    rText.nTop = nVolTop-TITLE_HEIGHT/2;
  }
  rText.nRight = rText.nLeft+LEFT_GAP_WIDTH;;
  rText.nBottom = nVolTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesBIAS[0]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop + nVolHeight/2 - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop + TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesBIAS[1]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop + nVolHeight - TITLE_HEIGHT;
	rText.nBottom = rText.nTop + TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesBIAS[2]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	int nPosT;
	nPosT = nPosStart + nPos;
	if (nPosT<0 || nPos < 0) {
		nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
	}
    
  //透明背景
  NSString *pStr;
  pStr = [NSString stringWithFormat:@"BIAS1:%.3f", pKIndex->BIAS.BIAS1[nPosT]];
  CGSize charSizeOne = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
  pStr = [NSString stringWithFormat:@"BIAS2:%.3f", pKIndex->BIAS.BIAS2[nPosT]];
  CGSize charSizeTwo = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
  pStr = [NSString stringWithFormat:@"BIAS3:%.3f", pKIndex->BIAS.BIAS3[nPosT]];
  CGSize charSizeThree = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
  rText.nLeft = LEFT_WIDTH(isLandscape) + 5;
  rText.nRight = rText.nLeft + charSizeOne.width + 10 + charSizeTwo.width + 10 + charSizeThree.width;
  rText.nTop = nVolTop + 4;
  rText.nBottom = rText.nTop + 9;
//DrawTools_FullARect(g, &rText, 0xf5f5f5, 0.5);
	
	//绘量标题
  rText.nLeft = 2*LEFT_GAP_WIDTH + 15;
  rText.nRight = self.frame.size.width;
	rText.nTop = nVolTop-TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
//	NSString *pStr;
	pStr = [NSString stringWithFormat:@"BIAS1:%.3f", pKIndex->BIAS.BIAS1[nPosT]];
	CGSize charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFFFF*/nM5Color, AGIN_LEFT);
	//因为显示不下，暂时不显示
	rText.nLeft = rText.nLeft+charSize.width+10;
	pStr = [NSString stringWithFormat:@"BIAS2:%.3f", pKIndex->BIAS.BIAS2[nPosT]];
	charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr),  /*0xFFFF00*/nM10Color, AGIN_LEFT);
	rText.nLeft = rText.nLeft+charSize.width+10;
	pStr = [NSString stringWithFormat:@"BIAS3:%.3f", pKIndex->BIAS.BIAS3[nPosT]];
	charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFF00FF*/nM20Color, AGIN_LEFT);
    
  //BIAS
  rText.nLeft = LEFT_GAP_WIDTH+15;
  rText.nRight = LEFT_GAP_WIDTH;
  rText.nTop = nVolTop - TITLE_HEIGHT;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, @"BIAS", nIndexsColor, AGIN_RIGHT);
}

-(void)drawARBR:(CGContextRef)g withCount:(int)nCount
{
	DrawTools_DrawPath(g, pLineAR, nCount, /*0xFFFFFF*/nM5Color);
	DrawTools_DrawPath(g, pLineBR, nCount, /*0xFFFF00*/nM10Color);
	
	GUI_RECT rText;
	
  rText.nLeft = GAP_X;
  rText.nTop = nVolTop;
  if(isLandscape){
    rText.nLeft = 0;
    rText.nTop = nVolTop-TITLE_HEIGHT/2;
  }
  rText.nRight = rText.nLeft+LEFT_GAP_WIDTH;;
  rText.nBottom = nVolTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesARBR[0]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop + nVolHeight/2 - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop+20;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesARBR[1]]), /*0x00AAFF*/nVolTitleColor,  AGIN(!isLandscape));
	
	rText.nTop = nVolTop + nVolHeight - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop+20;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesARBR[2]]), /*0x00AAFF*/nVolTitleColor,  AGIN(!isLandscape));
	
	
	int nPosT;
	nPosT = nPosStart + nPos;
	if (nPosT<0 || nPos < 0) {
		nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
	}
  
	//绘量标题
  rText.nLeft = 2*LEFT_GAP_WIDTH + 15;
  rText.nRight = self.frame.size.width;
	rText.nTop = nVolTop-TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	NSString *pStr;
	pStr = [NSString stringWithFormat:@"BR:%.3f", pKIndex->ARBR.BR[nPosT]];
	CGSize charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFFFF*/nM5Color, AGIN_LEFT);
	rText.nLeft = rText.nLeft+charSize.width+10;
	pStr = [NSString stringWithFormat:@"AR:%.3f", pKIndex->ARBR.AR[nPosT]];
	charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFF00*/nM10Color, AGIN_LEFT);
  
  //ARBR
  rText.nLeft = LEFT_GAP_WIDTH+15;
  rText.nRight = LEFT_GAP_WIDTH;
  rText.nTop = nVolTop - TITLE_HEIGHT;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, @"ARBR", nIndexsColor, AGIN_RIGHT);
}

-(void)drawCCI:(CGContextRef)g withCount:(int)nCount
{
	DrawTools_DrawPath(g, pLineCCI, nCount, 0x888888);
		
	GUI_RECT rText;
	
  rText.nLeft = GAP_X;
  rText.nTop = nVolTop;
  if(isLandscape){
    rText.nLeft = 0;
    rText.nTop = nVolTop-TITLE_HEIGHT/2;
  }
  rText.nRight = rText.nLeft+LEFT_GAP_WIDTH;;
  rText.nBottom = nVolTop+TITLE_HEIGHT;
  DrawTools_DrawNSFText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesCCI[0]]), nVolTitleColor, AGIN(!isLandscape), 9);
	
	rText.nTop = nVolTop + nVolHeight/2 - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop + TITLE_HEIGHT;
  DrawTools_DrawNSFText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesCCI[1]]), nVolTitleColor, AGIN(!isLandscape), 9);
	
	rText.nTop = nVolTop + nVolHeight - TITLE_HEIGHT;
	rText.nBottom = rText.nTop + TITLE_HEIGHT;
  DrawTools_DrawNSFText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesCCI[2]]), nVolTitleColor, AGIN(!isLandscape), 9);
	
	
	int nPosT;
	nPosT = nPosStart + nPos;
	if (nPosT<0 || nPos < 0) {
		nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
	}
    
  //透明背景
  NSString *pStr;
  pStr = [NSString stringWithFormat:@"CCI:%.3f", pKIndex->CCI.CCI[nPosT]];
  CGSize charSizeOne = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
  rText.nLeft = LEFT_WIDTH(isLandscape) + 5;
  rText.nRight = rText.nLeft + charSizeOne.width;
  rText.nTop = nVolTop + 4;
  rText.nBottom = rText.nTop + 9;
//    DrawTools_FullARect(g, &rText, 0xf5f5f5, 0.5);
	
	//绘量标题
  rText.nLeft = 2*LEFT_GAP_WIDTH+15;
  rText.nRight = self.frame.size.width-2*LEFT_GAP_WIDTH-15;
	rText.nTop = nVolTop-TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
//	NSString *pStr;
	pStr = [NSString stringWithFormat:@"CCI:%.3f", pKIndex->CCI.CCI[nPosT]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), 0x888888, AGIN_LEFT);
    
  //CCI
  rText.nLeft = LEFT_GAP_WIDTH+15;
  rText.nRight = LEFT_GAP_WIDTH;
  rText.nTop = nVolTop - TITLE_HEIGHT;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, @"CCI", nIndexsColor, AGIN_RIGHT);
}

-(void)drawBOLL:(CGContextRef)g withCount:(int)nCount
{
	for(int i=0; i<nUpLen; i++)
	{
		DrawTools_DrawLine(g, pBollUp[i].x, pBollUp[i].yHight, pBollUp[i].x, pBollUp[i].yLow, nUpFrameColor, 0);
		DrawTools_DrawLine(g, pBollUp[i].xOpen, pBollUp[i].yOpen, pBollUp[i].x, pBollUp[i].yOpen, nUpFrameColor, 0);
		DrawTools_DrawLine(g, pBollUp[i].xCur, pBollUp[i].yCur, pBollUp[i].x, pBollUp[i].yCur, nUpFrameColor, 0);
	}
	
	for(int i=0; i<nDownLen; i++)
	{
		DrawTools_DrawLine(g, pBollDown[i].x, pBollDown[i].yHight, pBollDown[i].x, pBollDown[i].yLow, /*0x00FFFF*/nDownFullColor, 0);
		DrawTools_DrawLine(g, pBollDown[i].xOpen, pBollDown[i].yOpen, pBollDown[i].x, pBollDown[i].yOpen, /*0x00FFFF*/nDownFullColor, 0);
		DrawTools_DrawLine(g, pBollDown[i].xCur, pBollDown[i].yCur, pBollDown[i].x, pBollDown[i].yCur, /*0x00FFFF*/nDownFullColor, 0);
	}
	
	DrawTools_DrawPath(g, pLineMID, nCount, /*0xFFFFFF*/nM5Color);
	DrawTools_DrawPath(g, pLineUPPER, nCount, /*0xFFFF00*/nM10Color);
	DrawTools_DrawPath(g, pLineLOWER, nCount, /*0xFF00FF*/nM20Color);
	
	GUI_RECT rText;
	
  rText.nLeft = GAP_X;
  rText.nTop = nVolTop;
  if(isLandscape){
    rText.nLeft = 0;
    rText.nTop = nVolTop-TITLE_HEIGHT/2;
  }
  rText.nRight = rText.nLeft+LEFT_GAP_WIDTH;;
  rText.nBottom = nVolTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesBOLL[0]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop +nVolHeight/2 - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesBOLL[1]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop +nVolHeight - TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesBOLL[2]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	int nPosT;
	nPosT = nPosStart + nPos;
	if (nPosT<0 || nPos < 0) {
		nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
	}
    
  //透明背景
  NSString *pStr;
  pStr = [NSString stringWithFormat:@"BOLL:(26,2)"];
  CGSize charSizeOne = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
  pStr = [NSString stringWithFormat:@"M:%.3f", pKIndex->BOLL.MID[nPosT]];
  CGSize charSizeTwo = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
  pStr = [NSString stringWithFormat:@"U:%.3f", pKIndex->BOLL.UPPER[nPosT]];
  CGSize charSizeThree = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
  pStr = [NSString stringWithFormat:@"L:%.3f", pKIndex->BOLL.LOWER[nPosT]];
  CGSize charSizeFour = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
  rText.nLeft = LEFT_WIDTH(isLandscape) + 5;
  rText.nRight = rText.nLeft + charSizeOne.width + 10 + charSizeTwo.width + 10 + charSizeThree.width + 10 + charSizeFour.width;
  rText.nTop = nVolTop + 4;
  rText.nBottom = rText.nTop + 9;
//    DrawTools_FullARect(g, &rText, 0xf5f5f5, 0.5);
	
	//绘量标题
	rText.nLeft = 2*LEFT_GAP_WIDTH+15;
	rText.nRight = self.frame.size.width-2*LEFT_GAP_WIDTH-15;
	rText.nTop = nVolTop-TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
//	NSString *pStr;
	pStr = [NSString stringWithFormat:@"BOLL:(26,2)"];
	CGSize charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFFFF*/nM5Color, AGIN_LEFT);
	//因为显示不下，暂时不显示
	rText.nLeft = rText.nLeft+charSize.width+10;
	pStr = [NSString stringWithFormat:@"M:%.3f", pKIndex->BOLL.MID[nPosT]];
	charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFFFF*/nM5Color, AGIN_LEFT);
	rText.nLeft = rText.nLeft+charSize.width+10;
	pStr = [NSString stringWithFormat:@"U:%.3f", pKIndex->BOLL.UPPER[nPosT]];
	charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFF00*/nM10Color, AGIN_LEFT);
	rText.nLeft = rText.nLeft+charSize.width+10;
	pStr = [NSString stringWithFormat:@"L:%.3f", pKIndex->BOLL.LOWER[nPosT]];
	charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFF00FF*/nM20Color, AGIN_LEFT);
    
  //BOLL
  rText.nLeft = LEFT_GAP_WIDTH+15;
  rText.nRight = LEFT_GAP_WIDTH;
  rText.nTop = nVolTop-TITLE_HEIGHT;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, @"BOLL", nIndexsColor, AGIN_RIGHT);
}

-(void)drawDMA:(CGContextRef)g withCount:(int)nCount
{
	DrawTools_DrawPath(g, pLineDDD, nCount, /*0xFFFFFF*/nM5Color);
	DrawTools_DrawPath(g, pLineAMA, nCount, /*0xFFFF00*/nM10Color);
	
	GUI_RECT rText;
	
  rText.nLeft = GAP_X;
  rText.nLeft = GAP_X;
  rText.nTop = nVolTop;
  if(isLandscape){
    rText.nLeft = 0;
    rText.nTop = nVolTop-TITLE_HEIGHT/2;
  }
  rText.nRight = rText.nLeft+LEFT_GAP_WIDTH;;
  rText.nBottom = nVolTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDMA[0]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop + nVolHeight/2 - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop + TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDMA[1]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	rText.nTop = nVolTop + nVolHeight - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop+20;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDMA[2]]), /*0x00AAFF*/nVolTitleColor, AGIN(!isLandscape));
	
	
	int nPosT;
	nPosT = nPosStart + nPos;
	if (nPosT<0 || nPos < 0) {
		nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
	}
	
	//绘量标题
  rText.nLeft = 2*LEFT_GAP_WIDTH+15;
  rText.nRight = LEFT_GAP_WIDTH;
	rText.nTop = nVolTop-TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	NSString *pStr;
	pStr = [NSString stringWithFormat:@"DDD:%.3f", pKIndex->DMA.DDD[nPosT]];
	CGSize charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFFFF*/nM5Color, AGIN_LEFT);
	rText.nLeft = rText.nLeft+charSize.width+10;
	pStr = [NSString stringWithFormat:@"AMA:%.3f", pKIndex->DMA.AMA[nPosT]];
	charSize = [pStr sizeWithFont:[UIFont systemFontOfSize:12]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFF00*/nM10Color, AGIN_LEFT);
  
  //DMA
  rText.nLeft = LEFT_GAP_WIDTH+15;
  rText.nRight = LEFT_GAP_WIDTH;
  rText.nTop = nVolTop-TITLE_HEIGHT;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, @"DMA", nIndexsColor, AGIN_RIGHT);
}

-(void)drawPSY:(CGContextRef)g withCount:(int)nCount
{
	DrawTools_DrawPath(g, pLinePSY, nCount, /*0xFFFFFF*/nM5Color);
	
	GUI_RECT rText;
	
  rText.nLeft = GAP_X;
  rText.nTop = nVolTop;
  if(isLandscape){
    rText.nLeft = 0;
    rText.nTop = nVolTop-TITLE_HEIGHT/2;
  }
  rText.nRight = rText.nLeft+LEFT_GAP_WIDTH;;
  rText.nBottom = nVolTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesPSY[0]]), /*0x00AAFF*/nVolTitleColor, AGIN_RIGHT);
	
	rText.nTop = nVolTop + nVolHeight/2 - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesPSY[1]]), /*0x00AAFF*/nVolTitleColor, AGIN_RIGHT);
	
	rText.nTop = nVolTop + nVolHeight - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesPSY[2]]), /*0x00AAFF*/nVolTitleColor, AGIN_RIGHT);
	
	
	int nPosT;
	nPosT = nPosStart + nPos;
	if (nPosT<0 || nPos < 0) {
		nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
	}
	
	//绘量标题
  rText.nLeft = 2*LEFT_GAP_WIDTH+15;
  rText.nRight = LEFT_GAP_WIDTH;
	rText.nTop = nVolTop-TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	NSString *pStr;
	pStr = [NSString stringWithFormat:@"PSY:%.3f", pKIndex->PSY.PSY[nPosT]];
	DrawTools_DrawNSText(g, &rText, (__bridge void *)(pStr), /*0xFFFFFF*/nM5Color, AGIN_LEFT);
  
  //PSY
  rText.nLeft = LEFT_GAP_WIDTH+15;
  rText.nRight = LEFT_GAP_WIDTH;
  rText.nTop = nVolTop - TITLE_HEIGHT;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, @"PSY", nIndexsColor, AGIN_RIGHT);
}

//lisz add 20110916 start
void DrawTools_FullPath (void * g, GUI_POINT  *points, int nLen, int nColor)
{
	CGContextRef context;
	context = (CGContextRef)g;
	
	if(context == nil) return;
	if(points==NULL)
	{
		return;
	}
	
	GUI_POINT  *p;
	p = points;
	
	CGFloat rr,gg,bb;
	rr = ((nColor>>16)&0xff)/255.0;
	gg = ((nColor>>8)&0xff)/255.0;
	bb = (nColor&0xff)/255.0;
	CGContextSetRGBFillColor(context, rr, gg, bb, 1.0);
	CGContextSetRGBStrokeColor(context, rr, gg, bb, 1.0);
  
	if(p->y<0 || nLen<=0)
	{
		return;
		
	}
	
	if (p->y>0) {
		CGContextMoveToPoint(context, p->x, p->y);
		for(int i=1; i<nLen; i++)
		{
			p = p+1;
			CGContextAddLineToPoint(context, p->x, p->y);
		}
	}
	else 
	{
		int i;
		for(i=1; i<nLen; i++)
		{
			if (p->y>0) {
				break;
			}
			p = p+1;
		}
		
		CGContextMoveToPoint(context, p->x, p->y);
		for(; i<nLen; i++)
		{
			p = p+1;
			CGContextAddLineToPoint(context, p->x, p->y);
		}
	}
  
	
	
	//CGContextStrokePath(context);
  CGContextFillPath(context);
  
}

void DrawTools_DrawPathWithLineWidth (void * g, GUI_POINT  *points, int nLen, int nColor, float fLineWidth)
{
	CGContextRef context;
	context = (CGContextRef)g;
	
	if(context == nil) return;
	if(points==NULL)
	{
		return;
	}
	
	GUI_POINT  *p;
	p = points;
	
	CGFloat rr,gg,bb;
	rr = ((nColor>>16)&0xff)/255.0;
	gg = ((nColor>>8)&0xff)/255.0;
	bb = (nColor&0xff)/255.0;
	CGContextSetRGBFillColor(context, rr, gg, bb, 1.0);
	CGContextSetRGBStrokeColor(context, rr, gg, bb, 1.0);
  
  CGContextSetLineWidth(context, fLineWidth);
  CGContextSetLineJoin(context, kCGLineJoinRound);//add by jason 线的风格
	if(p->y<0 || nLen<=0)
	{
		return;
		
	}
	
	if (p->y>0) {
		CGContextMoveToPoint(context, p->x, p->y);
		for(int i=1; i<nLen; i++)
		{
			p = p+1;
			CGContextAddLineToPoint(context, p->x, p->y);
		}
	}
	else 
	{
		int i;
		for(i=1; i<nLen; i++)
		{
			if (p->y>0) {
				break;
			}
			p = p+1;
		}
		
		CGContextMoveToPoint(context, p->x, p->y);
		for(; i<nLen; i++)
		{
			p = p+1;
			CGContextAddLineToPoint(context, p->x, p->y);
		}
	}
  
	
	
	CGContextStrokePath(context);
  
}

-(void)drawDDX:(CGContextRef)g withCount:(int)nCount
{
  GUI_RECT rText;
  
  int nPosT;
  
  if (nLineExType==KLINE_EX_TYPE_DDZ) {
    //ddz
    DrawTools_DrawPath(g, pDDX1, nCount, 0xFFFFFF);
    
    GUI_POINT point[5];
    
    
    for (int i=1; i<nCount; i++) {
      point[0].x = point[1].x = pDDX1[i].x;
      point[2].x = point[3].x = pDDX1[i-1].x;
      if ((pKIndex->DDZ.ddz1[i+nPosStart-1]*pKIndex->DDZ.ddz1[i+nPosStart])>0) {
        //在同一侧，即全红或全绿
        point[0].y = pDDX1[i].y;
        point[1].y = pDDX2[i].y;
        
        point[2].y = pDDX2[i-1].y;
        point[3].y = pDDX1[i-1].y;
        
        DrawTools_FullPath (g, point, 4, getColorRGW24(pKIndex->DDZ.ddz1[i+nPosStart],0));
      }
      else
      {
        point[0].y = pDDX1[i].y;
        point[1].y = pDDX2[i].y;
        
//        point[2].y = pDDX1[i-1].y;
//        point[3].y = pDDX2[i-1].y;
        
        point[2].y = pDDX1[i-1].y+(pDDX1[i].y-pDDX1[i-1].y)/2;
        point[2].x = pDDX1[i-1].x+(pDDX1[i].x-pDDX1[i-1].x)/2;
        //point[3].y = pDDX2[i-1].y;
        DrawTools_FullPath (g, point, 3, getColorRGW24(pKIndex->DDZ.ddz1[i+nPosStart],0));
        
        point[0].x = point[1].x = pDDX1[i-1].x;
        point[0].y = pDDX1[i-1].y;
        point[1].y = pDDX2[i-1].y;
        DrawTools_FullPath (g, point, 3, getColorRGW24(pKIndex->DDZ.ddz1[i+nPosStart-1],0));
      }

      //DrawTools_FullPath (g, point, 4, getColorRGW24(pKIndex->DDZ.ddz1[i+nPosStart],0));
    }
  }
  else//DDX,DDY
  {
    DrawTools_DrawLine(g, LEFT_WIDTH(isLandscape), nDDX_Y_0, self.frame.size.width, nDDX_Y_0, 0x676767, PEN_STYLE_DOTLINE);
    DrawTools_FullRectArr(g, pLineDDXUp, nDDX_DDUpLen, 0xFF0000);
    DrawTools_FullRectArr(g, pLineDDXDown, nDDX_DDDownLen, 0x00FFFF);
	  
    
    DrawTools_DrawPath(g, pDDX1, nCount, 0xFFFF00);
    DrawTools_DrawPath(g, pDDX2, nCount, 0xFF00FF);
    DrawTools_DrawPath(g, pDDX3, nCount, 0x00FF00);
  }
  
  rText.nLeft = 0;
  rText.nRight = LEFT_WIDTH(isLandscape);
  rText.nTop = nVolTop - TITLE_HEIGHT/2;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDDX[0]]), 0x00AAFF, AGIN_RIGHT);
  
  rText.nTop = nVolTop + nVolHeight/2 - TITLE_HEIGHT/2;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDDX[1]]), 0x00AAFF, AGIN_RIGHT);
  
  rText.nTop = nVolTop + nVolHeight - TITLE_HEIGHT/2;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDDX[2]]), 0x00AAFF, AGIN_RIGHT);
	
  nPosT = nPosStart + nPos;
  if (nPosT<0 || nPos<0) {
    nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
  }
	
	//绘量标题
	rText.nLeft = LEFT_WIDTH(isLandscape);
	rText.nRight = self.frame.size.width;
	rText.nTop = nVolTop-TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	NSString *pStr;
  float fontSize = 10.0;
  UIFont *pFont = [UIFont systemFontOfSize:fontSize];
  if (nLineExType==KLINE_EX_TYPE_DDX) {
    pStr = [NSString stringWithFormat:@"DDX:%.2f", pKIndex->DDX.ddx[nPosT]];
    CGSize charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFFFF, AGIN_LEFT,fontSize);
    rText.nLeft = rText.nLeft+charSize.width+5;
    pStr = [NSString stringWithFormat:@"DDX1:%.2f", pKIndex->DDX.ddx1[nPosT]];
    charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFF00, AGIN_LEFT,fontSize);
    rText.nLeft = rText.nLeft+charSize.width+5;
    pStr = [NSString stringWithFormat:@"DDX2:%.2f", pKIndex->DDX.ddx2[nPosT]];
    charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFF00FF, AGIN_LEFT,fontSize);
    rText.nLeft = rText.nLeft+charSize.width+5;
    pStr = [NSString stringWithFormat:@"DDX3:%.2f", pKIndex->DDX.ddx3[nPosT]];
    charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0x00FF00, AGIN_LEFT,fontSize);
  } else if (nLineExType==KLINE_EX_TYPE_DDY) {
    pStr = [NSString stringWithFormat:@"DDY:%.2f", pKIndex->DDY.ddy[nPosT]];
    CGSize charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFFFF, AGIN_LEFT,fontSize);
    rText.nLeft = rText.nLeft+charSize.width+5;
    pStr = [NSString stringWithFormat:@"DDY1:%.2f", pKIndex->DDY.ddy1[nPosT]];
    charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFF00, AGIN_LEFT,fontSize);
    rText.nLeft = rText.nLeft+charSize.width+5;
    pStr = [NSString stringWithFormat:@"DDY2:%.2f", pKIndex->DDY.ddy2[nPosT]];
    charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFF00FF, AGIN_LEFT,fontSize);
    rText.nLeft = rText.nLeft+charSize.width+5;
    pStr = [NSString stringWithFormat:@"DDY3:%.2f", pKIndex->DDY.ddy3[nPosT]];
    charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0x00FF00, AGIN_LEFT,fontSize);
  } else if (nLineExType==KLINE_EX_TYPE_DDZ) {
    pStr = [NSString stringWithFormat:@"DDZ:%.2f", pKIndex->DDZ.ddz[nPosT]];
    CGSize charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFFFF, AGIN_LEFT,fontSize);
    rText.nLeft = rText.nLeft+charSize.width+5;
    pStr = [NSString stringWithFormat:@"DDZ:%.2f", pKIndex->DDZ.ddz1[nPosT]];
    charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFF00, AGIN_LEFT,fontSize);
  }
	
  
}

///绘bbd主力、散户持仓
-(void)drawBBDRetaiMain:(CGContextRef)g withCount:(int)nCount
{
	GUI_RECT rText;
	
	int nPosT;
	
	  DrawTools_DrawPathWithLineWidth(g, pDDX1, nCount, 0xFFFFFF, 3.0);
	  DrawTools_FullRectArr(g, pLineDDXUp, nDDX_DDUpLen, 0xFF0000);
	  DrawTools_FullRectArr(g, pLineDDXDown, nDDX_DDDownLen, 0x00FF00);

	rText.nLeft = 0;
	rText.nRight = LEFT_WIDTH(isLandscape);
	rText.nTop = nVolTop - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDDX[0]]), 0x00AAFF, AGIN_RIGHT);
	
	rText.nTop = nVolTop + nVolHeight/2- TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDDX[1]]), 0x00AAFF, AGIN_RIGHT);

	rText.nTop = nVolTop + nVolHeight - TITLE_HEIGHT/2;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDDX[2]]), 0x00AAFF, AGIN_RIGHT);
	nPosT = nPosStart + nPos;
	if (nPosT<0 || nPos < 0) {
		nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
	}

	//绘量标题
	rText.nLeft = LEFT_WIDTH(isLandscape);
	rText.nRight = self.frame.size.width;
	rText.nTop = nVolTop-TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	NSString *pStr;
	float fontSize = 10.0;
	 UIFont *pFont = [UIFont systemFontOfSize:fontSize];
	if (nLineExType == KLINE_EX_TYPE_BBD_MAIN) {
		pStr = [NSString stringWithFormat:@"主力持仓:%.2f", pKIndex->BBDMain.shareholdingRatio[nPosT]];
		DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFFFF, AGIN_LEFT,fontSize);
		CGSize charSize = [pStr sizeWithFont:pFont];
		rText.nLeft = rText.nLeft+charSize.width+5;
		pStr = [NSString stringWithFormat:@"当日增减度:%.2f", pKIndex->BBDMain.currentFluctuation[nPosT]];
		charSize = [pStr sizeWithFont:pFont];
		DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFF00, AGIN_LEFT,fontSize);
	}else if (nLineExType == KLINE_EX_TYPE_BBD_RETAI) {
		pStr = [NSString stringWithFormat:@"散户持仓:%.2f", pKIndex->BBDRetai.shareholdingRatio[nPosT]];
		DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFFFF, AGIN_LEFT,fontSize);
		CGSize charSize = [pStr sizeWithFont:pFont];
		rText.nLeft = rText.nLeft+charSize.width+5;
		pStr = [NSString stringWithFormat:@"当日增减度:%.2f", pKIndex->BBDRetai.currentFluctuation[nPosT]];
		charSize = [pStr sizeWithFont:pFont];
		DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFF00, AGIN_LEFT,fontSize);
	}
	
}
///绘bbd净额
-(void)drawBBD:(CGContextRef)g withCount:(int)nCount
{
  GUI_RECT rText;
  
  int nPosT;
  
  
  DrawTools_DrawLine(g, LEFT_WIDTH(isLandscape), nDDX_Y_0, self.frame.size.width, nDDX_Y_0, 0x676767, PEN_STYLE_DOTLINE);
  DrawTools_FullRectArr(g, pLineDDXUp, nDDX_DDUpLen, 0xFF0000);
  DrawTools_FullRectArr(g, pLineDDXDown, nDDX_DDDownLen, 0x00FF00);
  
  DrawTools_DrawPath(g, pDDX1, nCount, 0xFFFF00);
  DrawTools_DrawPath(g, pDDX2, nCount, 0xFFFFFF);
  DrawTools_DrawPath(g, pDDX3, nCount, 0x00FF00);
  
  rText.nLeft = 0;
  rText.nRight = LEFT_WIDTH(isLandscape);
  rText.nTop = nVolTop - TITLE_HEIGHT/2;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  //DrawTools_DrawNSText(g, &rText, [NSString stringWithFormat:@"%@", VolSumShow(fScalesDDX[0])], 0x00AAFF, AGIN_RIGHT);
  float fontSize = 9.0;
  DrawTools_DrawNSFText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%@", VolSumShow(fScalesDDX[0])]), 0x00AAFF, AGIN_RIGHT,fontSize);
  rText.nTop = nVolTop + nVolHeight/2- TITLE_HEIGHT/2;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
	
  //DrawTools_DrawNSText(g, &rText, [NSString stringWithFormat:@"%@", VolSumShow(fScalesDDX[1])], 0x00AAFF, AGIN_RIGHT);
  DrawTools_DrawNSFText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%@", VolSumShow(fScalesDDX[1])]), 0x00AAFF, AGIN_RIGHT,fontSize);
	
  rText.nTop = nVolTop + nVolHeight - TITLE_HEIGHT/2;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  //DrawTools_DrawNSText(g, &rText, [NSString stringWithFormat:@"%@", VolSumShow(fScalesDDX[2])], 0x00AAFF, AGIN_RIGHT);
  DrawTools_DrawNSFText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%@", VolSumShow(fScalesDDX[2])]), 0x00AAFF, AGIN_RIGHT,fontSize);
  
  nPosT = nPosStart + nPos;
  if (nPosT<0 || nPos < 0) {
    nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
  }
	
	//绘量标题
	rText.nLeft = LEFT_WIDTH(isLandscape);
	rText.nRight = self.frame.size.width;
	rText.nTop = nVolTop-TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	NSString *pStr;
	fontSize = 10.0;

  pStr = [NSString stringWithFormat:@"BBD:%@元", VolSumShowL2(pKIndex->BBD.bbd[nPosT])];
  DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFF00FF, AGIN_LEFT,fontSize);
}

-(void)drawAvgVolSum:(CGContextRef)g withCount:(int)nCount
{
  GUI_RECT rText;
  
  int nPosT;
  
	
  DrawTools_FullRectArr(g, pLineDDXUp, nDDX_DDUpLen, 0xFF0000);
  
  rText.nLeft = 0;
  rText.nRight = LEFT_WIDTH(isLandscape);
  rText.nTop = nVolTop - TITLE_HEIGHT/2;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDDX[0]]), 0x00AAFF, AGIN_RIGHT);
  
  rText.nTop = nVolTop + nVolHeight/2 - TITLE_HEIGHT/2;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDDX[1]]), 0x00AAFF, AGIN_RIGHT);
  
  rText.nTop = nVolTop + nVolHeight- TITLE_HEIGHT/2;
  rText.nBottom = rText.nTop+TITLE_HEIGHT;
  DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDDX[2]]), 0x00AAFF, AGIN_RIGHT);
	
  nPosT = nPosStart + nPos;
  if (nPosT<0 || nPos < 0) {
    nPosT = pKRes->nTotalCount+pKRes->nKStartPos-1;
  }
	
	//绘量标题
	rText.nLeft = LEFT_WIDTH(isLandscape);
	rText.nRight = self.frame.size.width;
	rText.nTop = nVolTop - TITLE_HEIGHT;
	rText.nBottom = rText.nTop+TITLE_HEIGHT;
	NSString *pStr;
  float fontSize = 10.0;
  UIFont *pFont = [UIFont systemFontOfSize:fontSize];

  pStr = [NSString stringWithFormat:@"每笔均额:%.2f", pKIndex->AVG_VOL_SUM.avgSum[nPosT]];
  CGSize charSize = [pStr sizeWithFont:pFont];
  DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFF0000, AGIN_LEFT,fontSize);
  rText.nLeft = rText.nLeft+charSize.width+5;
  pStr = [NSString stringWithFormat:@"每笔均量:%.2f", pKIndex->AVG_VOL_SUM.avgVol[nPosT]];
  charSize = [pStr sizeWithFont:pFont];
  DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFF00, AGIN_LEFT,fontSize);
}
//lisz add 20110916 end

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(!pKRes){
        return;
    }
    UITouch *t = [touches anyObject];
    CGFloat x = [t locationInView:self].x;
    if (x >= self.frame.size.width - RIGHT_WIDTH(isLandscape)) {
        return;
    }
    
    isMoved = YES;
    if (isShow10Line) {//十字线显示 滑动移动十字线
        [self show10LineWithTouches:touches];
    }else{
        [self setKlineGestureWithTouches:touches];
    }
  
    bIsCalcStartPos = FALSE;
}

- (void)setKlineGestureWithTouches:(NSSet *)touches
{
    if([touches count]==1)
    {
        UITouch *t = [touches anyObject];
        CGFloat x = [t locationInView:self].x;
        CGFloat y = [t locationInView:self].y;
        
        if (x > nSwipeLastPoint.x) {//右侧清扫
            [self swipeOrientation:KSwipe_RIGHT_Orientation];
        }else if (x < nSwipeLastPoint.x){
            [self swipeOrientation:KSwipe_Left_Orientation];
        }
        
        nSwipeLastPoint.x = x;
        nSwipeLastPoint.y = y;
    }
    else if([touches count]==2)
    {
        nPos = -1;
        
        UITouch *t1 = [[touches allObjects] objectAtIndex:0];
        UITouch *t2 = [[touches allObjects] objectAtIndex:1];
        
        int nMTWidthNew = abs([t1 locationInView:self].x - [t2 locationInView:self].x);
        
        if (nMTWidthOld==0) {
            nMTWidthOld = nMTWidthNew;
            return;
        }
        
        if (nMTWidthNew>nMTWidthOld && (nMTWidthNew-nMTWidthOld) >nMTDistance)
        {
            //在放大
            [self addKLineWidth];
            [self setNeedsDisplay];
            nMTWidthOld = nMTWidthNew;
        }
        else if( (nMTWidthNew-nMTWidthOld)< (0-nMTDistance) )
        {
            //在缩小
            [self subKLineWidth];
            [self setNeedsDisplay];
            nMTWidthOld = nMTWidthNew;
        }
    }

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//    if(!pKRes)
//    {
//        return;
//    }
//  
//    if (!isMoved) {
//        isShow10Line = !isShow10Line;
//        [self show10LineWithTouches:touches];
//    }
//    isMoved = NO;
//    if (nPosStart == pKRes->nKStartPos) {
//        nSwipeLastPoint = CGPointZero;
//    }
//    if (nPosStart == (pKRes->nTotalCount+pKRes->nKStartPos - [self KLine_DrawMaxNumber])) {
//        nSwipeLastPoint = CGPointMake(self.frame.size.width, 0);
//    }
}

- (void)show10LineWithTouches:(NSSet *)touches
{
    UITouch *t = [touches anyObject];
    [self show10LineWithLocation:[t locationInView:self]];
}

- (void)show10LineWithLocation:(CGPoint)location
{
    int x = location.x;
    int y = location.y;
    
    if (y<TITLE_HEIGHT || x<LEFT_WIDTH(isLandscape)) {
        return;
    }
    
    //计算十字线位置
    nPos = (x-LEFT_WIDTH(isLandscape)-1)/(nKLineWidth+SA_WIDTH);
    if(nPosStart+nPos>=(pKRes->nTotalCount+pKRes->nKStartPos))
    {
        nPos = pKRes->nTotalCount+pKRes->nKStartPos - nPosStart - 1;
    }
    
    //固定纵坐标于收盘价
    int posX = LEFT_WIDTH(isLandscape) + 1 + SA_WIDTH + (nPos*(nKLineWidth+SA_WIDTH))+ nKLineWidth/2;
    for (int i = 0; i < nUpLen; i++) {
        if (pUp[i].x == posX) {
            ty = pRectUp[i].nTop;
        }
    }
    for (int n = 0; n < nDownLen; n++) {
        if (pDown[n].x == posX) {
            ty = pRectDown[n].nBottom;
        }
    }
    
    [self setNeedsDisplay];
    
    [self.parent upToParentWithObjc:@(isShow10Line) withType:KMSClickIsShowTenLineActionType withParamter:[self p_packageMinPriceModel]];

}
- (HZMinPriceModel *)p_packageMinPriceModel
{
    NSInteger nIndex = nPosStart+nPos;
    if (!isShow10Line) {
        nIndex = pKRes->nMaxCount - 1;
    }
    
    QUOTELV_K_POINT *kPoint = &pKRes->kData[nIndex];
    float fPre = kPoint->fOpen;
    if (nIndex >= 1) {
        QUOTELV_K_POINT *kPrePoint = &pKRes->kData[nIndex - 1];
        fPre = kPrePoint->fCur;
    }
    HZMinPriceModel *model = [HZMinPriceModel new];
    model.model_currentPrice = D_PriShow(kPoint->fCur, "2");
    model.model_zhangDie = D_PriShowE(kPoint->fCur,fPre,"2");
    model.model_zhangFu = DRShow(kPoint->fCur, fPre);
    model.model_maxPrice = D_PriShow(kPoint->fHigh,"2");
    model.model_minPrice = D_PriShow(kPoint->fLow,"2");
    model.model_openPrice = D_PriShow(kPoint->fOpen, "2");
    model.model_prePrice = D_PriShow(fPre,"2");
    model.model_chengJiaoE = VolSumShow(kPoint->lSum/100);
    model.model_chengJiaoLiang = VolSumShow(kPoint->lVol);
    return model;
}
- (void)swipeOrientation:(int)orientation
{
    if (pKRes->nTotalCount<=[self KLine_DrawMaxNumber]) {
        return;
    }
    if (orientation == KSwipe_RIGHT_Orientation) {
        nPosStart--;
    }else if (orientation == KSwipe_Left_Orientation){
        nPosStart++;
    }
    
    if (nPosStart<pKRes->nKStartPos) {
        nPosStart = pKRes->nKStartPos;
    }
    else if(nPosStart>(pKRes->nTotalCount+pKRes->nKStartPos - [self KLine_DrawMaxNumber]))
    {
        nPosStart = pKRes->nTotalCount+pKRes->nKStartPos - [self KLine_DrawMaxNumber];
    }
    
    [self calcData];
    [self setNeedsDisplay];
}

- (void)movePul:(NSTimer*)timer
{
	BOOL b = NO;
	if (pKRes->nTotalCount<=[self KLine_DrawMaxNumber]) {
		return;
	}
	int x;
	x = nPos*(nKLineWidth+SA_WIDTH)+LEFT_WIDTH(isLandscape);
	
	if (x<LEFT_WIDTH(isLandscape)+40) {
		nPosStart--;
		b = YES;
	}
	else if(x>self.frame.size.width - RIGHT_WIDTH(isLandscape) -40)
	{
		nPosStart++;
		b = YES;
	}

	//if (nPos<=5) {
//		nPosStart--;
//		b = YES;
//	}
//	else if(nPos>=[self KLine_DrawMaxNumber]-5)
//	{
//		nPosStart++;
//		b = YES;
//	}
	if (nPosStart<pKRes->nKStartPos) {
		nPosStart = pKRes->nKStartPos;
	}
	else if(nPosStart>(pKRes->nTotalCount+pKRes->nKStartPos - [self KLine_DrawMaxNumber]))
	{
		nPosStart = pKRes->nTotalCount+pKRes->nKStartPos - [self KLine_DrawMaxNumber];
	}
	
	if (b) {
		[self calcData];
		[self setNeedsDisplay];
	}
	
}

-(void)setMulDelegate:(id <KLineChartDelegate>)anObject
{
	self.delegate = anObject;
}

-(void)formatShowDate:(int)nDate withDis:(char*)sBuf
{
	char sTemp[64];
	memset(sTemp, 0, sizeof(sTemp));
	sprintf(sTemp, "%lld", DateTimeInt2Long(nDate));
	//日期8位
	sBuf[0]=0x00;
	sBuf[8]=0x00;
	switch (pKRes->kLineType) {
		case QUOTELV_K_DATE://date
		case QUOTELV_K_WEEK://week
		case QUOTELV_K_MONTH://month
			memcpy(sBuf, sTemp, 8);
			break;
		case QUOTELV_K_1MIN:
		case QUOTELV_K_5MIN:
		case QUOTELV_K_15MIN:
		case QUOTELV_K_30MIN:
		case QUOTELV_K_60MIN:
			memcpy(sBuf, sTemp+4,8);
		default:
			break;
	}
}

-(void)upMulData
{
	[self movePos:nPosStart+nPos];
}

-(void)movePos:(int)nIndex
{
	if (self.delegate)
	{
		
		//nIndex = ( nIndex > nPos+nPosStart - 1) ? nPos+nPosStart - 1 : nIndex;
		char sShowDate[64];
		memset(sShowDate, 0, sizeof(sShowDate));
		[self formatShowDate:pKRes->kData[nIndex].nDate withDis:sShowDate];
		
		//幅度计算
		float fRange = 0;
		float fZF = 0;
		float fZD = 0;
			if (nIndex == 0) {
				fRange = 0;
				fZD = 0;
			}else {
				fZD = pKRes->kData[nIndex].fCur - pKRes->kData[nIndex-1].fCur;
				fRange = fZD / pKRes->kData[nIndex-1].fCur * 100;
			}
		fZF = (pKRes->kData[nIndex].fHigh - pKRes->kData[nIndex].fLow) / pKRes->kData[nIndex].fLow *100;

		NSArray *dataArray;
		NSArray *colorArray;
		if (nIndex==0)
		{
			dataArray = [NSArray arrayWithObjects:
								@"涨幅",
								[NSString stringWithFormat:@"%.2f%@",fRange,@"%"],
								 @"开盘",
								 D_PriShow(pKRes->kData[nIndex].fOpen, pKRes->codeinfo.decNum),
								@"涨跌",
								[NSString stringWithFormat:@"%.2f",fZD],
								 @"最高",
								 D_PriShow(pKRes->kData[nIndex].fHigh, pKRes->codeinfo.decNum),
								 @"振幅",
								 [NSString stringWithFormat:@"%.2f%@",fZF,@"%"],
								 @"最低",
								 D_PriShow(pKRes->kData[nIndex].fLow, pKRes->codeinfo.decNum),
								 @"换手",
								 SwpShow2(pKRes->kData[nIndex].fSwap),
								@"收盘",
								D_PriShow(pKRes->kData[nIndex].fCur, pKRes->codeinfo.decNum),
								nil];
			
			colorArray = [NSArray arrayWithObjects:
						  [UIColor whiteColor],//涨幅
						  getColorRGW(fRange, 0),
							[UIColor whiteColor],//开盘
							getColorRGW(pKRes->kData[nIndex].fOpen, pKRes->kData[nIndex].fOpen),
							[UIColor whiteColor],//涨跌
							getColorRGW(fZD, 0),
						  [UIColor whiteColor],//最高
						  getColorRGW(pKRes->kData[nIndex].fHigh, pKRes->kData[nIndex].fOpen),
							[UIColor whiteColor],//振幅
							_rgb2uic(nVolTitleColor,1.0),/*[UIColor blackColor],*/
						  [UIColor whiteColor],//最低
						  getColorRGW(pKRes->kData[nIndex].fLow, pKRes->kData[nIndex].fOpen),
							[UIColor whiteColor],//换手
							_rgb2uic(nVolTitleColor,1.0),/*[UIColor blackColor],*/
							[UIColor whiteColor],//收盘
							getColorRGW(pKRes->kData[nIndex].fCur, pKRes->kData[nIndex].fOpen),
						  nil];
		}
		else
		{
			dataArray = [NSArray arrayWithObjects:
									 @"涨幅",
									 [NSString stringWithFormat:@"%.2f%@",fRange,@"%"],
									 @"开盘",
									 D_PriShow(pKRes->kData[nIndex].fOpen, pKRes->codeinfo.decNum),
									 @"涨跌",
									 [NSString stringWithFormat:@"%.2f",fZD],
									 @"最高",
									 D_PriShow(pKRes->kData[nIndex].fHigh, pKRes->codeinfo.decNum),
									 @"振幅",
									 [NSString stringWithFormat:@"%.2f%@",fZF,@"%"],
									 @"最低",
									 D_PriShow(pKRes->kData[nIndex].fLow, pKRes->codeinfo.decNum),
									 @"换手",
									 SwpShow2(pKRes->kData[nIndex].fSwap),
									 @"收盘",
									 D_PriShow(pKRes->kData[nIndex].fCur, pKRes->codeinfo.decNum),
									 nil];
			
			//printf("\n i is %d m is %s",nIndex,[SwpShow2(pKRes->kData[nIndex].fSwap) UTF8String]);
			
			//colorArray = [NSArray arrayWithObjects:
//						  [UIColor whiteColor],//日期
//						  [UIColor blackColor],
//						  [UIColor whiteColor],//收盘
//						  getColorRGW(pKRes->kData[nIndex].fCur, pKRes->kData[nIndex].fOpen),
//						  [UIColor whiteColor],//开盘
//						  getColorRGW(pKRes->kData[nIndex].fOpen, pKRes->kData[nIndex-1].fCur),
//						  [UIColor whiteColor],//最高
//						  getColorRGW(pKRes->kData[nIndex].fHigh, pKRes->kData[nIndex].fOpen),
//						  [UIColor whiteColor],//最低
//						  getColorRGW(pKRes->kData[nIndex].fLow, pKRes->kData[nIndex].fOpen),
//						  [UIColor whiteColor],//成交量
//						  [UIColor blackColor],
//						  [UIColor whiteColor],//成交额
//						  [UIColor blackColor],
//							[UIColor whiteColor],//成交额
//							[UIColor blackColor],
//						  nil];
			colorArray = [NSArray arrayWithObjects:
										[UIColor whiteColor],//幅
										getColorRGW(fRange, 0),
										[UIColor whiteColor],//开盘
										getColorRGW(pKRes->kData[nIndex].fOpen, pKRes->kData[nIndex - 1].fOpen),
										[UIColor whiteColor],//涨跌
										getColorRGW(fZD, 0),
										[UIColor whiteColor],//最高
										getColorRGW(pKRes->kData[nIndex].fHigh, pKRes->kData[nIndex].fOpen),
										[UIColor whiteColor],//振
										_rgb2uic(nVolTitleColor,1.0),/*[UIColor blackColor],*/
										[UIColor whiteColor],//最低
										getColorRGW(pKRes->kData[nIndex].fLow, pKRes->kData[nIndex].fOpen),
										[UIColor whiteColor],//换
										_rgb2uic(nVolTitleColor,1.0),/*[UIColor blackColor],*/
										[UIColor whiteColor],//收盘
										getColorRGW(pKRes->kData[nIndex].fCur, pKRes->kData[nIndex].fOpen),
										nil];
		}
		[self.delegate movePul:dataArray withColor:colorArray];
		
		//[dataArray release];
		//[colorArray release];
	}
}

-(int)getAbsPos
{
	return nPosStart+nPos;
}

-(void)hiddedPul
{
	nPos = -1;
	[self setNeedsDisplay];
}

-(void)OnChangeView:(int)n
{
	nPos = -1;
  //计算数据
	[self calcData];
	[self setNeedsDisplay];
}

- (void)setCalcStartPos:(BOOL)bStartPos{
   bIsCalcStartPos = bStartPos;
}

- (void)dealloc {
}

- (void)setSubChartIndex:(NSInteger)tag
{
    int nIndexs;
    switch (tag) {
        case 0:
            nIndexs = KLINE_EX_TYPE_VOL;
            break;
        case 1:
            nIndexs = KLINE_EX_TYPE_MACD;
            break;
        case 2:
            nIndexs = KLINE_EX_TYPE_KDJ;
            break;
        case 3:
            nIndexs = KLINE_EX_TYPE_RSI;
            break;
        case 4:
            nIndexs = KLINE_EX_TYPE_BIAS;
            break;
        case 5:
            nIndexs = KLINE_EX_TYPE_BOLL;
            break;
        case 6:
            nIndexs = KLINE_EX_TYPE_CCI;
            break;
        case 7:
            nIndexs = KLINE_EX_TYPE_WR;
            break;
        case 8:
            nIndexs = KLINE_EX_TYPE_DMA;
            break;
        case 9:
            nIndexs = KLINE_EX_TYPE_ARBR;
            break;
        case 10:
            nIndexs = KLINE_EX_TYPE_PSY;
            break;
        default:
            break;
    }
    
    [self setCurShowIndex:nIndexs];
}

-(void)setCurShowIndex:(int)n
{
  nLineExType = n;
	nDDX_Y_0 = 0;//add by jason
	nDDX_DDUpLen = 0; 
	nDDX_DDDownLen = 0;
  [self calcData];
  [self setNeedsDisplay];
}

-(int)getShowIndex
{
  return nLineExType;
}

#pragma mark ======= 绘图method
- (void)drawNewLine:(CGContextRef)context startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint color:(int)nColor lineWidth:(int)lineWidth{
    
    if(context == nil) return;
    
    CGFloat rr,gg,bb;
    rr = ((nColor>>16)&0xff)/255.0;
    gg = ((nColor>>8)&0xff)/255.0;
    bb = (nColor&0xff)/255.0;
    
    CGContextSetLineWidth(context, lineWidth);
    
    CGContextSetRGBFillColor(context, rr, gg, bb, 1.0);
    CGContextSetRGBStrokeColor(context, rr, gg, bb, 1.0);
    
//    CGContextSetAllowsAntialiasing(context, NO);
    CGContextSetShouldAntialias(context, NO);
    
    CGContextMoveToPoint(context, startPoint.x, startPoint.y);
    CGContextAddLineToPoint(context, endPoint.x, endPoint.y);
    
    CGContextClosePath(context);
    CGContextStrokePath(context);
    CGContextSetShouldAntialias(context, NO);
    
}

#pragma mark =====================
#pragma mark 涨跌颜色判断
-(int)isUpOrDown:(int)i
{
	int nflag;
	float fPreClose;
	if (i > 0) {
		fPreClose = pKRes->kData[i-1].fCur;
	} else {
		fPreClose = pKRes->kData[0].fCur;
	}
	
	int nCur;
	nCur = (pKRes->kData[i].fCur * pow(10, pKRes->codeinfo.decNum)+0.5);
	int nOpen;
	nOpen = (pKRes->kData[i].fOpen * pow(10, pKRes->codeinfo.decNum)+0.5);
	if(nCur == nOpen){
		if(pKRes->kData[i].fCur >= fPreClose){
			nflag = 1;
		}else{
			nflag = -1;
		}
	} else {
		if(pKRes->kData[i].fCur >= pKRes->kData[i].fOpen){
			nflag = 1;
		} else {
			nflag = -1;
		}
	}
	
	return nflag;
}

#pragma mark ===========
#pragma mark 设置显示模式
-(void)setMode:(int)nMode
{
	n_Mode = nMode;
    mLeftView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, LEFT_GAP_WIDTH, 20)];
    mLeftView.backgroundColor = [UIColor grayColor];
    mLeftView.layer.cornerRadius = 10;
    mLeftView.layer.masksToBounds = YES;
		mLeftView.hidden = YES;
		UILabel *left = [[UILabel alloc] initWithFrame:mLeftView.frame];
		left.textColor = [UIColor whiteColor];
		left.textAlignment = UITextAlignmentCenter;
		left.backgroundColor = [UIColor clearColor];
		left.font = [UIFont systemFontOfSize:8];
		[mLeftView addSubview:left];
		mLeft = left;
		
		mBottomView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, LEFT_GAP_WIDTH, 20)];
//  [mBottomView setImage:[UIImage imageNamed:@"arrow_up.png"]];
    mBottomView.backgroundColor = [UIColor grayColor];
    mBottomView.layer.cornerRadius = 10;
    mBottomView.layer.masksToBounds = YES;
		mBottomView.hidden = YES;
		UILabel *bottom = [[UILabel alloc] initWithFrame:mBottomView.frame];
		bottom.textColor = [UIColor whiteColor];
		bottom.textAlignment = NSTextAlignmentCenter;
		bottom.backgroundColor = [UIColor clearColor];
		bottom.font = [UIFont systemFontOfSize:8];
		[mBottomView addSubview:bottom];
		mBottom = bottom;
    
//    mVerButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    mVerButton.backgroundColor = _rgb2uic(0x2f5895, 1);
//    mVerButton.tag = 0;
//      mVerButton.titleLabel.font = [UIFont systemFontOfSize:9];
//    [mVerButton setTitle:@"换横屏" forState:UIControlStateNormal];
//    [mVerButton setTitleColor:_rgb2uic(0xf5f5f5, 1) forState:UIControlStateNormal];
//    [mVerButton.layer setMasksToBounds:YES];
//    [mVerButton.layer setCornerRadius:3.0]; //设置矩形四个圆角半径
//    [mVerButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
    
    mAveButton = [UIButton buttonWithType:UIButtonTypeCustom];
    mAveButton.backgroundColor = _rgb2uic(0x2f5895, 1);
    mAveButton.tag = 1;
      mAveButton.titleLabel.font = [UIFont systemFontOfSize:9];
    [mAveButton setTitle:@"设均线" forState:UIControlStateNormal];
    [mAveButton setTitleColor:_rgb2uic(0xf5f5f5, 1) forState:UIControlStateNormal];
    [mAveButton.layer setMasksToBounds:YES];
    [mAveButton.layer setCornerRadius:3.0]; //设置矩形四个圆角半径
    [mAveButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
    
    mIndexButton = [UIButton buttonWithType:UIButtonTypeCustom];
    mIndexButton.backgroundColor = _rgb2uic(0x2f5895, 1);
    mIndexButton.tag = 2;
      mIndexButton.titleLabel.font = [UIFont systemFontOfSize:9];
    [mIndexButton setTitle:@"选指标" forState:UIControlStateNormal];
    [mIndexButton setTitleColor:_rgb2uic(0xf5f5f5, 1) forState:UIControlStateNormal];
    [mIndexButton.layer setMasksToBounds:YES];
    [mIndexButton.layer setCornerRadius:3.0]; //设置矩形四个圆角半径
    [mIndexButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
    
    mComplexButton = [UIButton buttonWithType:UIButtonTypeCustom];
    mComplexButton.backgroundColor = _rgb2uic(0x2f5895, 1);
    mComplexButton.tag = 3;
      mComplexButton.titleLabel.font = [UIFont systemFontOfSize:9];
    [mComplexButton setTitle:@"不复权" forState:UIControlStateNormal];
    [mComplexButton setTitleColor:_rgb2uic(0xf5f5f5, 1) forState:UIControlStateNormal];
    [mComplexButton.layer setMasksToBounds:YES];
    [mComplexButton.layer setCornerRadius:3.0]; //设置矩形四个圆角半径
    [mComplexButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
		//

    CGRect btnRect = CGRectMake(self.frame.size.width-(23+10)*4, 200, 23, 23);
    mLeftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [mLeftButton setBackgroundImage:[UIImage imageNamed:@"btn_left_move_default@2x.png"] forState:UIControlStateNormal];
    mLeftButton.tag = 4;
    [mLeftButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
    
    mRightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [mRightButton setBackgroundImage:[UIImage imageNamed:@"btn_right_move_default@2x.png"] forState:UIControlStateNormal];
    mRightButton.tag = 5;
    [mRightButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
    
    mDownButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [mDownButton setBackgroundImage:[UIImage imageNamed:@"btn_zoom_down_default@2x.png"] forState:UIControlStateNormal];
    mDownButton.tag = 6;
    [mDownButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
    
    mUpButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [mUpButton setBackgroundImage:[UIImage imageNamed:@"btn_zoom_up_default@2x.png"] forState:UIControlStateNormal];
    mUpButton.tag = 7;
    [mUpButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
    
    mLeftButton.frame = mRightButton.frame = mDownButton.frame = mUpButton.frame = btnRect;
//    [self addSubview:mVerButton];
    [self addSubview:mAveButton];
    [self addSubview:mIndexButton];
    [self addSubview:mComplexButton];
    [self addSubview:mLeftView];
    [self addSubview:mBottomView];
    [self addSubview:mLeftButton];
    [self addSubview:mRightButton];
    [self addSubview:mDownButton];
    [self addSubview:mUpButton];
}

- (void)buttonActive:(id)sender{
    NSInteger indexTag = ((UIButton *)sender).tag;
    if (indexTag == 0) {
        [self.parent upToParentWithObjc:self withType:KMSKlineChartViewType withParamter:[NSNumber numberWithInteger:0]];
    }else if(indexTag == 1){
        [self.parent upToParentWithObjc:self withType:KMSKlineChartViewType withParamter:@"Change_MA"];
    }else if(indexTag == 2){
        [self.parent upToParentWithObjc:self withType:KMSKlineChartViewType withParamter:@"Change_Index"];
    }else if(indexTag == 3){
        if([mComplexButton.currentTitle isEqualToString:@"不复权"]){//除权
            [mComplexButton setTitle:@"前复权" forState:UIControlStateNormal];
            [self.parent upToParentWithObjc:self withType:KMSKlineChartViewType withParamter:@"NO_Complex"];
    }else if([mComplexButton.currentTitle isEqualToString:@"前复权"]){
        [mComplexButton setTitle:@"不复权" forState:UIControlStateNormal];
        [self.parent upToParentWithObjc:self withType:KMSKlineChartViewType withParamter:@"Pre_Complex"];
    }
  }else if(indexTag == 4){//左滑
    [self swipeOrientation:KSwipe_Left_Orientation];
  }else if(indexTag == 5){//右滑
    [self swipeOrientation:KSwipe_RIGHT_Orientation];
  }else if(indexTag == 6){//缩小
    [self subKLineWidth];
    [self setNeedsDisplay];
  }else if(indexTag == 7){//放大
    [self addKLineWidth];
    [self setNeedsDisplay];
  }
}

- (void)changeIndex:(NSString *)indexName{
  
  if([indexName isEqualToString:@"VOL"]){
    nLineExType = KLINE_EX_TYPE_VOL;
  }else if([indexName isEqualToString:@"MACD"]){
    nLineExType = KLINE_EX_TYPE_MACD;
  }else if([indexName isEqualToString:@"KDJ"]){
    nLineExType = KLINE_EX_TYPE_KDJ;
  }else if([indexName isEqualToString:@"RSI"]){
    nLineExType = KLINE_EX_TYPE_RSI;
  }else if([indexName isEqualToString:@"BIAS"]){
    nLineExType = KLINE_EX_TYPE_BIAS;
  }else if([indexName isEqualToString:@"BOLL"]){
    nLineExType = KLINE_EX_TYPE_BOLL;
  }else if([indexName isEqualToString:@"CCI"]){
    nLineExType = KLINE_EX_TYPE_CCI;
  }else if([indexName isEqualToString:@"WR"]){
    nLineExType = KLINE_EX_TYPE_WR;
  }else if([indexName isEqualToString:@"DMA"]){
    nLineExType = KLINE_EX_TYPE_DMA;
  }else if([indexName isEqualToString:@"ARBR"]){
    nLineExType = KLINE_EX_TYPE_ARBR;
  }else if([indexName isEqualToString:@"PSY"]){
    nLineExType = KLINE_EX_TYPE_PSY;
  }
  
  [self setCurShowIndex:nLineExType];
}
- (void)OnChangeTheme:(int)nThemeId withPath:(NSString*)path{
  if(nThemeId == 1){
    self.backgroundColor = kMYHexToRGB(0x2e2f40,1);
    frameColor = 0x3b4050;//0xdddddd
    scalesLineColor = 0x3b4050;//0xdddddd
    [mVerButton setTitleColor:_rgb2uic(0x8c96b4, 1) forState:UIControlStateNormal];
    [mAveButton setTitleColor:_rgb2uic(0x8c96b4, 1) forState:UIControlStateNormal];
    [mIndexButton setTitleColor:_rgb2uic(0x8c96b4, 1) forState:UIControlStateNormal];
    [mComplexButton setTitleColor:_rgb2uic(0x8c96b4, 1) forState:UIControlStateNormal];
  }else{
    self.backgroundColor = [UIColor clearColor];
    frameColor = 0xdddddd;
    scalesLineColor = 0xdddddd;
    [mVerButton setTitleColor:_rgb2uic(0xf5f5f5, 1) forState:UIControlStateNormal];
    [mAveButton setTitleColor:_rgb2uic(0xf5f5f5, 1) forState:UIControlStateNormal];
    [mIndexButton setTitleColor:_rgb2uic(0xf5f5f5, 1) forState:UIControlStateNormal];
    [mComplexButton setTitleColor:_rgb2uic(0xf5f5f5, 1) forState:UIControlStateNormal];
  }
}

#pragma mark -
- (void)upToParentWithObjc:(id)objc withType:(NSInteger)type withParamter:(id)paramter{
}
- (void)downToChildWithObjc:(id)objc withType:(NSInteger)type withParamter:(id)paramter{
    switch (type) {
        case kHZ_cancelLandscapeScreen_Action:
        {
            pLandScapeBtn.hidden = NO;
        }
            break;
            
        default:
            break;
    }
}

@end
